In Kubernetes, the default pattern is that we do not inject the environment flag into the applications as .NET suggests. [1] Instead, we inject configuration, both defaults
(can be overridden) and the specific configuration into the container.
The following .NET codes set up the configuration as follows:
new ConfigurationBuilder() .AddJsonFile("appsettings.defaults.json", optional: false, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build()
I suspect from [1] that the above snippet loads all JSON keys first from appsettings.defaults.json
and then loads all JSON keys from appsettings.json
and then when there are matching keys from appsettings.json
, those will override keys in the first appsettings.defaults.json
.
Both appsettings.defaults.json
and appsettings.json
are provided in the /app
folder and their content is correct. However, only keys and values from appsettings.json
is used, and configuration from appsettings.defaults.json
is not used at all.
Is the above code should work and if so, what could be the problem elsewhere? [1] does define how it works and also links to a code snippet that is similar to the above but uses {env.HostEnvironment}
of some sort that I do not need. It is easier to have a single name for it when I'm developing a Helm chart in Kubernetes.
Thanks!