- reference this package to your project: https://www.nuget.org/packages/Samhammer.Configuration.Childs/
To add it to ASP.NET Core configuration simply place .EnableChildSubstitutions() last. Make sure it is always called after all other configurations are added, else it won't behave properly!
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, builder) =>
{
// if you have any additional configuration place it before
var customer = Environment.GetEnvironmentVariable("CUSTOMER");
builder.EnableChildSubstitutions(customer);
});Set enviroment variable 'Customer' to control which child substitutions are loaded in the configuration. For local development you can do set in launchsettings.json.
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"CUSTOMER": "customer1"
}If you want to deploy multiple production systems (e.g. different customers) and you don´t want to add additional appsettings.json files or additional enviroment variables for all of your settings.
Example where the entry ConnectionString in appsettings.json has some default value and some substitutions values for different customers.
{
"ConnectionString ": "blabla&catalog=myapp",
"customer1:ConnectionString ": "blabla&catalog=myapp-customer1",
"customer2:ConnectionString ": "blabla&catalog=myapp-customer2",
}var value = configuration["ConnectionString"];This will return 'blabla&catalog=myapp-customer1'.
{
"DatabaseOptions ": {
"HostName": "host",
"CatalogName": "db",
"UserName": "user"
},
"customer1:DatabaseOptions": {
"CatalogName": "db1",
"UserName": "user1"
}
}{
"DatabaseOptions ": {
"HostName": "host",
"CatalogName": "db",
"UserName": "user",
"customer1": {
"CatalogName": "db1",
"UserName": "user1"
}
}
}- Create a tag and let the github action do the publishing for you