10 Configuring an ASP.NET Core application

 

This chapter covers

  • Loading settings from multiple configuration providers
  • Storing sensitive settings safely
  • Using strongly typed settings objects
  • Using different settings in different hosting environments

In part 1 of this book, you learned the basics of getting an ASP.NET Core app up and running, and how to use minimal API endpoints to create an HTTP API. When you start building real applications, you’ll quickly find that you want to tweak various settings at deploy time without necessarily having to recompile your application. This chapter looks at how you can achieve this task in ASP.NET Core by using configuration.

I know. Configuration sounds boring, right? But I have to confess that the configuration model is one of my favorite parts of ASP.NET Core; it’s so easy to use and so much more elegant than some approaches in old versions of .NET Framework. In section 10.2 you’ll learn how to load values from a plethora of sources—JavaScript Object Notation (JSON) files, environment variables, and command-line arguments—and combine them into a unified configuration object.

10.1 Introducing the ASP.NET Core configuration model

10.2 Building a configuration object for your app

10.2.1 Adding a configuration provider in Program.cs

10.2.2 Using multiple providers to override configuration values

10.2.3 Storing configuration secrets safely

10.2.4 Reloading configuration values when they change

10.3 Using strongly typed settings with the options pattern

10.3.1 Introducing the IOptions interface

10.3.2 Reloading strongly typed options with IOptionsSnapshot

10.3.3 Designing your options classes for automatic binding

10.3.4 Binding strongly typed settings without the IOptions interface

10.4 Configuring an application for multiple environments

10.4.1 Identifying the hosting environment

10.4.2 Loading environment-specific configuration files

sitemap