Learning the options interfaces
There are four main interfaces to use settings:
IOptionsMonitor<TOptions>
IOptionsFactory<TOptions>
IOptionsSnapshot<TOptions>
IOptions<TOptions>
We must inject one of those interfaces into a class to use the available settings. TOptions
is the type that represents the settings that we want to access.
The framework returns an empty instance of your options class if you don’t configure it. We learn how to configure options properly in the next subsection; meanwhile, remember that using property initializers inside your options class can also be a great way to ensure certain defaults are used. You can also use constants to centralize those defaults somewhere in your codebase (making them easier to maintain). Proper configuration and validation are always preferred, but both combined can add a safety net.
Don’t use initializers or constants for default values that change...