Configuration Sources & Providers
Layer configuration from JSON files, environment variables, command-line args, and custom providers with priority.
Configuration in .NET
ASP.NET Core's configuration system reads settings from multiple sources — JSON files, environment variables, command-line args, and more — and merges them into one flat key-value store accessible anywhere in your app.
appsettings.json
appsettings.json is the default configuration file. It is loaded automatically by Host.CreateApplicationBuilder. Settings are merged with environment-specific overrides.
// appsettings.json
{
"App": {
"Name": "OrderService",
"MaxRetries": 3
},
"ConnectionStrings": {
"Default": "Server=localhost;Database=orders"
}
}
// appsettings.Production.json overrides the above:
{
"ConnectionStrings": {
"Default": "Server=prod-db;Database=orders;..."
}
}All lessons in this course
- Configuration Sources & Providers
- Strongly Typed Options with IOptions
- Options Validation & Named Options
- Secrets Management