Skip to content

Latest commit

 

History

History
16 lines (14 loc) · 835 Bytes

File metadata and controls

16 lines (14 loc) · 835 Bytes

ASP.NET Core Options pattern

  • Options pattern is the default way to map settings from Microsoft.Extensions.Configuration to objects
  • Configure using dependency injection
    • services.AddOptions().Bind(configuration.GetSection("..."));
    • Add validation if needed
  • The consumer of a configuration object can decide, how to react on configuration changes
    • IOptions: Get the values set when the application started
    • IOptionsSnapshop: Get current values
    • IOptionsMonitor: Subscribe for configuration changes

Things to consider

  • Where you want to react on configuration changes during runtime of the application

Recommendation

  • Use Options pattern with IOptions by default
  • Use IOptionsSnapshop and IOptionsMonitor where needed. The reaction on configurations changes should be testet