My understanding is that, in .NET Core, child appsettings files, e.g. appsettings.development.json
, inherit from the parent appsettings.json
(in much the same way that, say, C# derived classes inherit from parent classes, unless explicitly overridden) – as long as in your startup logic you include code like the following:
IConfigurationBuilder configBuilder = new ConfigurationBuilder()
.AddJsonFile("parent_appsettings")
.AddJsonFile("child_appsettings");
configbuilder.Build();
This is not happening, however, in my situation. I have a parent appsettings.json
defined somewhat like the following:
{
"Section1" {
"Key1": "Value1"
},
"Section2" {
"Key2": "Value2"
}
}
And in my child appsettings.development.json
I have something like this:
{
"Section2" {
"Key2": "OverriddenValue2"
}
}
While this works when I run config.GetSection("Section2").GetValue("Key2")
(i,e, the value OverriddenValue2
is returned), it does not work when I try config.GetSection("Section1").GetValue("Key1")
. It thinks the section/key is missing, instead of automatically pulling down the section/value from the parent appsettings.
Is this how it’s supposed to work?