Configurationvar builder = new ConfigurationBuilder();builder.AddInMemoryCollection();var config = builder.Build();config["somekey"] = "somevalue";// do some other workvar setting = config["somekey"]; // also returns "somevalue"{ "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebApplication1-26e8893e-d7c0-4fc6-8aab-29b59971d622;Trusted_Connection=True;MultipleActiveResultSets=true" }, "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" } }}// work with with a builder using multiple callsvar builder = new ConfigurationBuilder();builder.SetBasePath(Directory.GetCurrentDirectory());builder.AddJsonFile("appsettings.json");var connectionStringConfig = builder.Build();// chain calls together as a fluent APIvar config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .AddEntityFrameworkConfig(options => options.UseSqlServer(connectionStringConfig.GetConnectionString("DefaultConnection")) ) .Build();public Startup(IHostingEnvironment env){ var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); if (env.IsDevelopment()) { // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709 builder.AddUserSecrets(); } builder.AddEnvironmentVariables(); Configuration = builder.Build();} public static void Main(string[] args) { var builder = new ConfigurationBuilder(); Console.WriteLine("Initial Config Sources: " + builder.Sources.Count()); builder.AddInMemoryCollection(new Dictionary{ { "username", "Guest" } }); Console.WriteLine("Added Memory Source. Sources: " + builder.Sources.Count()); builder.AddCommandLine(args); Console.WriteLine("Added Command Line Source. Sources: " + builder.Sources.Count()); var config = builder.Build(); string username = config["username"]; Console.WriteLine($"Hello, {username}!"); }-----------------------------------------------------------------------------------------Using Options and configuration objectspublic class MyOptions{ public string Option1 { get; set; } public int Option2 { get; set; }}public class HomeController : Controller{ private readonly IOptions _optionsAccessor; public HomeController(IOptions optionsAccessor) { _optionsAccessor = optionsAccessor; } // GET: / / public IActionResult Index() => View(_optionsAccessor.Value);}public void ConfigureServices(IServiceCollection services){ // Setup options with DI services.AddOptions(); // Configure MyOptions using config by installing Microsoft.Extensions.Options.ConfigurationExtensions services.Configure (Configuration); // Configure MyOptions using code services.Configure (myOptions => { myOptions.Option1 = "value1_from_action"; }); // Configure MySubOptions using a sub-section of the appsettings.json file services.Configure (Configuration.GetSection("subsection")); // Add framework services. services.AddMvc();}---------------------------------------------------------------------------------------Writing custom providerspublic class ConfigurationValue{ public string Id { get; set; } public string Value { get; set; }}public class ConfigurationContext : DbContext{ public ConfigurationContext(DbContextOptions options) : base(options) { } public DbSet Values { get; set; }}public class EntityFrameworkConfigurationSource : IConfigurationSource { private readonly Action _optionsAction; public EntityFrameworkConfigurationSource(Action optionsAction) { _optionsAction = optionsAction; } public IConfigurationProvider Build(IConfigurationBuilder builder) { return new EntityFrameworkConfigurationProvider(_optionsAction); } } public class EntityFrameworkConfigurationProvider : ConfigurationProvider { public EntityFrameworkConfigurationProvider(Action optionsAction) { OptionsAction = optionsAction; } Action OptionsAction { get; } public override void Load() { var builder = new DbContextOptionsBuilder (); OptionsAction(builder); using (var dbContext = new ConfigurationContext(builder.Options)) { dbContext.Database.EnsureCreated(); Data = !dbContext.Values.Any() ? CreateAndSaveDefaultValues(dbContext) : dbContext.Values.ToDictionary(c => c.Id, c => c.Value); } } private static IDictionary CreateAndSaveDefaultValues( ConfigurationContext dbContext) { var configValues = new Dictionary { { "key1", "value_from_ef_1" }, { "key2", "value_from_ef_2" } }; dbContext.Values.AddRange(configValues .Select(kvp => new ConfigurationValue { Id = kvp.Key, Value = kvp.Value }) .ToArray()); dbContext.SaveChanges(); return configValues; } } public static class EntityFrameworkExtensions { public static IConfigurationBuilder AddEntityFrameworkConfig( this IConfigurationBuilder builder, Action setup) { return builder.Add(new EntityFrameworkConfigurationSource(setup)); } }using System;using System.IO;using Microsoft.EntityFrameworkCore;using Microsoft.Extensions.Configuration;namespace CustomConfigurationProvider{ public static class Program { public static void Main() { // work with with a builder using multiple calls var builder = new ConfigurationBuilder(); builder.SetBasePath(Directory.GetCurrentDirectory()); builder.AddJsonFile("appsettings.json"); var connectionStringConfig = builder.Build(); // chain calls together as a fluent API var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .AddEntityFrameworkConfig(options => options.UseSqlServer(connectionStringConfig.GetConnectionString("DefaultConnection")) ) .Build(); Console.WriteLine("key1={0}", config["key1"]); Console.WriteLine("key2={0}", config["key2"]); Console.WriteLine("key3={0}", config["key3"]); } }}