liveBook · Manning

Chapter 10: Configuring an ASP.NET Core application

What you will learn in chapter 10 of ASP.NET Core in Action, 3e

This introduction explains why ASP.NET Core configuration lets applications change settings at deployment time and previews configuration providers, strongly typed options, and hosting environments.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains why ASP.NET Core configuration lets applications change settings at deployment time and previews configuration providers, strongly typed options, and hosting environments.

Key terms: configuration, deploy time, recompile, configuration providers, JSON, environment variables, command-line arguments, configuration object, strongly typed options objects, POCO

10.1 Introducing the ASP.NET Core configuration model

This section defines ASP.NET Core configuration, explains why settings and secrets should live outside compiled code, and introduces providers, overrides, and strongly typed binding.

Key terms: configuration, settings, secrets, connection string, API key, externalize, deploy time, source control, compiled code, configuration providers

10.2 Building a configuration object for your app

This section introduces how ASP.NET Core assembles application configuration from providers and how to organize values in appsettings.json.

Key terms: ConfigurationManager, IConfigurationBuilder, IConfigurationRoot, IConfiguration, IConfigurationProvider, key-value pairs, configuration providers, appsettings.json, configuration section, MapSettings

10.2.1 Adding a configuration provider in Program.cs

This section explains how WebApplicationBuilder creates and exposes configuration, how to add or replace configuration providers, and how to read configuration values through IConfiguration.

Key terms: WebApplicationBuilder, ConfigurationManager, Configuration, JSON file provider, User Secrets, environment variables, configuration provider, AddJsonFile, optional, FileNotFoundException

10.2.2 Using multiple providers to override configuration values

This section explains how multiple configuration providers combine into one IConfiguration and why providers added later override earlier values with the same key.

Key terms: ConfigurationManager, configuration provider, IConfiguration, configuration key, overwrite, appsettings.json, environment variables, connection strings

10.2.3 Storing configuration secrets safely

This section explains how to keep sensitive configuration out of source control by using environment variables in production and User Secrets during local development.

Key terms: appsettings.json, source control, environment variables, User Secrets, Azure Key Vault, AddEnvironmentVariables, ConfigurationManager, IConfiguration, MapSettings:MaxNumberOfPoints, MapSettings__MaxNumberOfPoints

10.2.4 Reloading configuration values when they change

This section explains how file-based configuration can reload automatically when its source file changes, avoiding application recompilation or restart.

Key terms: configuration reloading, appsettings.json, IConfiguration, Debug, Warning, Error, Add*File, reloadOnChange, ConfigurationManager, file-based configuration provider

10.3 Using strongly typed settings with the options pattern

This section introduces the options pattern as ASP.NET Core’s preferred approach for binding related configuration values into strongly typed POCO settings objects.

Key terms: strongly typed settings, IConfiguration, options pattern, POCO, options class, MapSettings, AppDisplaySettings, configuration section, configuration binder, binding

10.3.1 Introducing the IOptions interface

This section introduces IOptions<T> for registering, binding, and injecting strongly typed configuration settings, including its singleton and reload limitations.

Key terms: strongly typed settings, POCO options class, IConfiguration, single-responsibility principle, SRP, binding, options class, public parameterless constructor, public properties, ConfigurationSection

10.3.2 Reloading strongly typed options with IOptionsSnapshot

This section explains how IOptionsSnapshot<T> reloads strongly typed configuration per request, and the lifetime and performance trade-offs of using it instead of IOptions<T>.

Key terms: IOptions<T>, IOptionsSnapshot<T>, POCO options object, IConfiguration, AppDisplaySettings, scoped service, singleton service, captive dependency, IOptionsMonitor<T>, rebinding

10.3.3 Designing your options classes for automatic binding

This section explains how to design POCO options classes so the configuration binder can instantiate them and bind their properties automatically.

Key terms: POCO, IOptions<T>, binder, reflection, public parameterless constructor, configuration binder, getter, setter, set-only property, indexer

10.3.4 Binding strongly typed settings without the IOptions interface

This section shows how to bind and inject a strongly typed settings object directly, without requiring consumers to depend on IOptions<T>, and explains the trade-offs.

Key terms: configuration binder, IConfiguration, configuration section, MapSettings, dependency injection, IOptions<T>, singleton, lambda, DI container, IOptions<T>.Value

10.4 Configuring an application for multiple environments

This section introduces hosting environments as a way to identify where an ASP.NET Core app runs and use appropriate configuration values for that environment.

Key terms: hosting environments, development, production, configuration values, connection string, logging, hosting environment, current environment

10.4.1 Identifying the hosting environment

This section explains how ASP.NET Core identifies the hosting environment and how an app can use that environment information to vary its behavior and configuration.

Key terms: WebApplicationBuilder, ASPNETCORE_ENVIRONMENT, DOTNET_ENVIRONMENT, IHostEnvironment, WebApplicationBuilder.Environment, EnvironmentName, Development, Staging, Production, IsDevelopment()

10.4.2 Loading environment-specific configuration files

This section shows how the hosting environment selects configuration sources and application behavior, while keeping environment-specific concerns out of application services.

Key terms: EnvironmentName, appsettings.json, appsettings.Development.json, appsettings.Staging.json, appsettings.Production.json, ConfigurationManager, IHostEnvironment, configuration provider, User Secrets provider, Azure Key Vault

10.4.3 Setting the hosting environment

This section explains how to select an ASP.NET Core hosting environment locally and in production using environment variables, launch profiles, or command-line arguments.

Key terms: ASPNETCORE_ENVIRONMENT, hosting environment, Production, Development, launchSettings.json, launch profile, http profile, https profile, IIS Express profile, dotnet run --launch-profile

10.5 Summary

This summary recaps how ASP.NET Core loads, overrides, secures, binds, reloads, and environment-scopes application configuration.

Where this is used later

Concepts explained in this chapter

← Chapter 9: Registering services with dependency injection Chapter 11: Documenting APIs with OpenAPI →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.