Skip to content

thinkabouthub/Configuration.EntityFramework

Repository files navigation

onfiguration.EntityFramework

For .NET Framework & .NET Core

.NET Core supports a variety of different configuration options. Application configuration data can come from files using built-in support for JSON, XML, and INI formats, as well as from environment variables, command line arguments or even an in-memory collection. So why is there no support for EntityFramework? Well now there is!

Configuration.EntityFramework is a custom configuration provider for the .NET Core Configuration system. It's built on EntityFrameworkCore allowing configuration settings to be stored in a wide variety of repositories, including;

  • Microsoft SQL Server,
  • SQLite,
  • Npgsql (PostgreSQL),
  • MySQL (Official),
  • Pomelo (MySQL),
  • Microsoft SQL Server Compact Edition,
  • IBM Data Servers,
  • InMemory (for Testing),
  • Devart (MySQL, Oracle, PostgreSQL, SQLite, DB2, SQL Server, and more),
  • Oracle (Coming Soon).

Build Status

configuration-entityframework MyGet Build Status

So why use Configuration.EntityFramework?

Some settings, such as a connection string or those required during the initialisation of an application may be better located in a local file rather than a repository. However, in many cases Configuration.EntityFramework can present some distinct advantages, including;

  1. Makes use of the .NET Core configuration provider model,
  2. Support for complex types,
  3. Access settings in a strongly typed fashion using the [Options pattern] (https://docs.asp.net/en/latest/fundamentals/configuration.html#options-config-objects),
  4. Enhanced Configuration Management and Change Control. This is particularly relevant to a distributed environment,
  5. Transactional update of settings for whole of environment,
  6. Common settings can be shared among many applications. Support for single point of change,
  7. In a complex system with many related applications or services it's not uncommon to have many configuration files. By persisting settings to a database, the dependency on these configuration files can be reduced,
  8. All settings for a select criteria, such as environment, application or section can be retrieved with a single query,
  9. Allow end users to update settings via the EntityFramework Context.

Compatibility

Configuration.EntityFramework is compatible with netstandard2.0, net461 and net462.

How do I get started?

Our Sample Project demonstrates how to use Configuration.EntityFramework and gives you some starting points for learning more. Additionally, the Getting Started tutorial walks you through using Configuration.EntityFramework in a simple ASP.NET Core app.

Get Packages

You can get Configuration.EntityFramework by grabbing the latest NuGet package. If you're feeling adventurous, continuous integration builds are on MyGet.

Release notes are available on the wiki.

Get Help

Need help with Configuration.EntityFramework? We're ready to answer your questions on Stack Overflow. Alternatively ask a question here.

##Super-duper quick start

Create Configuration.EntityFramework database.

var options = new DbContextOptionsBuilder<ConfigurationContext>().UseSqlServer(
      @"Data Source=.;Initial Catalog=Configuration;Integrated Security=True").Options;

using (var context = new ConfigurationContext(options))
{
  context.Database.EnsureCreated();
}

Initialise Configuration.EntityFramework.

var config = new ConfigurationBuilder()
   .SetBasePath(Environment.CurrentDirectory)
   .AddJsonFile("appsettings.json", true, true)
   .AddEntityFrameworkConfig(builder => builder.UseSqlServer(@"Data Source=.;Initial Catalog=Configuration;Integrated Security=True"))
   .Build();

Check Configuration Section Exists.

var exists = config.SectionExists("SampleSection");

Get Configuration Section for complex type. Return null if section does not exist.

var section = config.TryGetSection<ComplexType>("SampleSection");

Get Configuration Section for complex type. Return default value if section does not exist.

var section = config.GetSection<ComplexType>("SampleSection");

Get Configuration Value for Key.

var setting = config.GetValue<string>("TestSetting");

Project

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages