What values should be in appsetting.json?

Viewed 52

In the modern .net application there is a default config file - appsettings.json. From the best practices, what values should I put in this file?

From my understanding, I should keep something that is commonly used by any environment in the system. Am I correct here?

For example, I have a dummy config key that has different values in each of my environments. I define the value for this key in appsetting.Development.json, appsetting.Production.json, etc. What is the best option for appsetting.json in this case - omit it or provide a fallback value or keep empty?

1 Answers

I believe this page answers your question quite well:

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-6.0

From the page above:

The default JsonConfigurationProvider loads configuration in the following order:

  1. appsettings.json
  2. appsettings.{Environment}.json

For example, the appsettings.Production.json and appsettings.Development.json files. The environment version of the file is loaded based on the IHostingEnvironment.EnvironmentName.

appsettings.{Environment}.json values override keys in appsettings.json.

Related