Chapter 11. 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 the MVC design pattern to create a traditional web app or a Web API. Once you start building real applications, you will quickly find that you want to tweak various settings at runtime, without having to recompile your application. This chapter looks at how you can achieve this in ASP.NET Core using configuration.

I know. Configuration sounds boring, right? But I have to confess, 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 the previous version of ASP.NET. In section 11.2, you’ll learn how to load values from a plethora of sources—JSON files, environment variables, and command-line arguments—and combine them into a unified configuration object.

On top of that, ASP.NET Core brings the ability to easily bind this configuration to strongly typed options objects. These are simple, POCO classes that are populated from the configuration object, which you can inject into your services, as you’ll see in section 11.3. This lets you nicely encapsulate settings for different features in your app.

11.1. Introducing the ASP.NET Core configuration model

11.2. Configuring your application with CreateDefaultBuilder

11.3. Building a configuration object for your app

11.4. Using strongly typed settings with the options pattern

11.5. Configuring an application for multiple environments

Summary