Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created April 17, 2021 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/3a246a0d107214fb0524b736dd7d71e1 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/3a246a0d107214fb0524b736dd7d71e1 to your computer and use it in GitHub Desktop.
In Memory Configuration Provider Sample
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