IConfigurationRoot represents the assembled configuration values available to an ASP.NET Core application. Configuration providers supply key-value pairs, and the root stores the resulting configuration, including values from sources such as JSON files, environment variables, and command-line arguments. section 10.2
Relate IConfigurationRoot to the surrounding configuration APIs:
- IConfigurationBuilder describes how to construct configuration; IConfigurationRoot holds the resulting values. section 10.2
- ConfigurationManager implements both interfaces and adds provider values to its root immediately in .NET 6 and .NET 7. section 10.2.1
- Application code generally consumes the IConfiguration interface; dependency injection registers ConfigurationManager as IConfiguration rather than IConfigurationRoot. section 10.2.1
Loading and reading configuration
A minimal application can clear the default sources, add an optional appsettings.json provider, and expose the assembled values with app.Configuration.AsEnumerable(). Endpoint handlers can instead receive IConfiguration through dependency injection and read nested keys such as MapSettings:DefaultZoomLevel. section 10.2.1
Figure 10.2 Using ConfigurationManager to populate IConfiguration. Configuration providers are added to the ConfigurationManager with extension methods. The manager queries the provider and adds all the returned values to the IConfigurationRoot, which implements IConfiguration.
Shows how ConfigurationManager queries providers and populates the IConfigurationRoot that implements IConfiguration. section 10.2
