liveBook · Manning

IConfigurationRoot

As explained in ASP.NET Core in Action, 3e

IConfigurationRoot is the .NET configuration interface representing the assembled configuration values and their providers.

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.
CH10_F02_Lock3

Shows how ConfigurationManager queries providers and populates the IConfigurationRoot that implements IConfiguration. section 10.2

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines the interface relationship and provider flow, but stops short of detailing IConfigurationRoot members or implementation internals.
Examples
Uses appsettings.json, nested MapSettings values, provider selection, AsEnumerable, and dependency-injected IConfiguration.
What it assumes
Assumes familiarity with ASP.NET Core configuration providers and introduces the relationship between builders, roots, and IConfiguration.
What you can do after
Evaluate/understand how providers populate application configuration and why application code usually consumes IConfiguration.
How it connects
Connects IConfigurationBuilder, ConfigurationManager, IConfiguration, configuration providers, dependency injection, and configuration keys.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.