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. Once you start building real applications, you will 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 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 some previous approaches in old versions of .NET Framework. In section 10.3 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 10.3. This lets you nicely encapsulate settings for different features in your app.