The Configuration System
Set `ConnectionStrings:Default` in appsettings.json, then export that same setting as an environment variable. The exported value silently wins, even though you never reopened the JSON file and never told anything which source to prefer.
- ▸A nested JSON key and a
__env var resolve to one colon key; values are strings. - ▸Stack position sets priority, not source type: an env var beats committed JSON only by being added later.
- ▸Save
appsettings.jsonand a running app sees it; change an env var and nothing moves until restart.
An appsettings.json looks like a tree:
{
"ConnectionStrings": { "Default": "Host=db;Port=5432" },
"Logging": { "LogLevel": { "Default": "Information" } },
"FeatureEnabled": true
}But the system that reads it keeps no tree. It flattens every leaf into one long list of string-to-string pairs, joining the nesting with a colon:
ConnectionStrings:Default = Host=db;Port=5432 Logging:LogLevel:Default = Information FeatureEnabled = True
That is the whole store: a flat dictionary where the path through the JSON becomes a single string key. There is no nested object in memory, only "Logging:LogLevel:Default" pointing at a string. Notice FeatureEnabled: the JSON boolean true arrives as the string "True". Every value is text, the typing happens later, when you read it back out. You reach a value by its full colon path, and IConfiguration is the service that holds the dictionary and answers those lookups.