How do you design a strongly-typed class for a configuration?

To create a strongly-typed class for binding to a configuration section:

  • The property names and their types match the key names and their value types "exactly" in the configuration.
  • The classes used must be non-abstract with parameterless constructors
  • Only the public accessors (properties) are bound to configuration data but not fields

How can you bind a configuration section to an object?

A Configuration section can be bound to a strictly-typed class object in two ways:

  • use Configuration.Bind() by passing the configuration section to bind and the object to which the values are mapped.
  • use services.Configure() to bind a section to a type and access the type by means of IOptions, IOptionsSnapshot or IOptionMonitor interface.