AddOptions
The registration call, services.AddOptions<T>(), that returns an options builder on which binding and validation calls are chained.
In more detail
Each call on it adds one more step, such as binding or a validation rule, to how the options are produced. BindConfiguration("Catalog") binds a section by path and follows reloads; Bind takes a section object you already have.
Example
services.AddOptions<CatalogOptions>().BindConfiguration(CatalogOptions.SectionName)Related terms
- options pattern — Binding a configuration section to a plain class with typed properties, validating it, and injecting it into services instead of reading raw strings.
- ValidateOnStart — The options-builder call that makes the host validate options while starting and refuse to start if they are invalid.
- ValidateDataAnnotations — The options-builder call that checks a bound options object against the data annotation attributes on its properties.
- fluent API — An API designed so each call returns an object you can call the next method on, letting configuration read as one chained sentence.
Taught in
- The Options Pattern: Strongly Typed Configuration — Modern .NET Core, C# & Enterprise Microservices