Advertisement
Beginner ASP.NET Core, Configuration & Options Pattern

How does ASP.NET Core's configuration system layer multiple sources together, and what is the default provider precedence?

Short answer

IConfiguration builds a unified key-value tree by combining multiple providers in registration order, where later-registered providers override earlier ones for the same key -- the default host builder registers appsettings.json first, then appsettings.{Environment}.json, then…

Save ASP.NET Core mock interview
Advertisement
AModel answer
IConfiguration builds a unified key-value tree by combining multiple providers in registration order, where later-registered providers override earlier ones for the same key -- the default host builder registers appsettings.json first, then appsettings.{Environment}.json, then user secrets (Development only), then environment variables, then command-line arguments, giving environment variables and command-line args the ability to override file-based settings, essential for containerized deployments.
// Precedence (later overrides earlier):
// appsettings.json -> appsettings.Production.json -> environment variables -> command-line args

// appsettings.json: "ConnectionStrings:Db": "local-connection"
// Environment variable ConnectionStrings__Db overrides it at deploy time
Real-world example
A containerized application ships with a generic appsettings.json for local development, while the actual production connection string is injected via a Kubernetes environment variable, overriding the file-based default without needing separate builds per environment.
Likely follow-ups
  • Why does the environment variable provider use double underscores instead of colons for nested keys?
  • How would you add a custom configuration source, like a database provider?
Related topics