The Options pattern
With ASP.NET Core, we can use predefined mechanisms to enhance the usage of application settings. These allow us to divide our configuration into multiple smaller objects, configure them during multiple stages of the startup flow, validate them, and even watch for runtime changes with minimal effort.
The Options pattern’s goal is to use settings at runtime, allowing changes to the application to happen without changing the code. The settings could be as simple as a string
, a bool
, a database connection string, or a complex object that holds an entire subsystem’s configuration.
This section explores different tools offered by ASP.NET Core to manage, inject, and load configurations and options into our programs. We will tackle different scenarios, from common ones to more advanced ones.
Getting started
The Options pattern in ASP.NET Core allows us to seamlessly load settings from multiple sources. We can customize these sources when...