Loading the configuration
ASP.NET Core allows us to load settings from multiple sources seamlessly by using configuration providers. We can customize these sources from the WebApplicationBuilder, or use the defaults set by the WebApplication.CreateBuilder(args) method.
The default sources, in order, are as follows:
appsettings.jsonappsettings.{Environment}.json- User secrets; these are only loaded when the environment is
Development - Environment variables
- Command-line arguments
The order is essential, as the last to be loaded overrides previous values. For example, you can set a value in appsettings.json and override it in appsettings.Staging.json by redefining the value in that file, user secrets, or an environment variable or by passing it as a command-line argument when you run your application.
You can name your environments as you want, but by default, ASP.NET Core has built-in helper methods for Development, Staging,...