Skip to main content

What is the purpose of IOptions, IOptionsSnapshot, and IOptionsMonitor?

Entry .NET Core
Quick Answer IOptions: reads config once at startup รขโ‚ฌโ€ singleton, doesn't pick up changes after app starts. IOptionsSnapshot: reads config per request รขโ‚ฌโ€ picks up changes between requests. IOptionsMonitor: reads config and reacts to changes in real-time via OnChange callback รขโ‚ฌโ€ ideal for configs that need live updates without restart.

Answer

These abstractions implement the Options pattern for working with configuration-bound classes.

  • IOptions<T> โ€“ A singleton snapshot of configuration, read once at startup.
  • IOptionsSnapshot<T> โ€“ A scoped snapshot that is recalculated per request; useful for web apps where config might change between requests.
  • IOptionsMonitor<T> โ€“ Supports change notifications and is ideal for long-lived components that need to react to configuration changes at runtime.

They allow strongly typed configuration without scattering configuration reads throughout the codebase.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice