Created
April 17, 2021 18:36
-
-
Save manoj-choudhari-git/3a246a0d107214fb0524b736dd7d71e1 to your computer and use it in GitHub Desktop.
In Memory Configuration Provider Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
CreateHostBuilder(args).Build().Run(); | |
} | |
public static IHostBuilder CreateHostBuilder(string[] args) | |
{ | |
// Populate the configuration settings somehow | |
// E.g. hard-coding or loading from other source. | |
var inMemoryConfigSettings = new Dictionary<string, string>() | |
{ | |
{ "Mode", "MemoryConfigProvider" }, | |
{ "MailFeature:0:Subject", "Dev Subject Marketing" }, | |
{ "MailFeature:1:Subject", "Dev Subject Users" }, | |
{ "MailFeature:2:Subject", "Dev Subject Orders" }, | |
{ "Logging:LogLevel:Default", "Error" } | |
}; | |
// AddInMemoryCollection to load these settings as key-value pairs | |
// so that they can be available via IConfiguration instance. | |
return Host.CreateDefaultBuilder(args) | |
.ConfigureAppConfiguration((hostingContext, config) => | |
{ | |
config.AddInMemoryCollection(inMemoryConfigSettings); | |
}) | |
.ConfigureWebHostDefaults(webBuilder => | |
{ | |
webBuilder.UseStartup<Startup>(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment