📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is the difference between IOptions<T>, IOptionsSnapshot<T> and IOptionsMonitor<T>, and which do you use when configuration can change at run time?

Intermediate Theory Intermediate

🎯 Key points

  • IOptions: singleton, bound once, never refreshes
  • IOptionsSnapshot: scoped lifetime (per HTTP request in ASP.NET Core), re-binds per scope
  • Snapshot in a singleton is a captive dependency; use IServiceScopeFactory or the monitor instead
  • IOptionsMonitor: singleton, CurrentValue cached until reload, OnChange callback
  • Performance: Snapshot pays a bind per request; Monitor is cheap per read
  • Named options supported by Snapshot and Monitor via Get(name)

⏱ 30-second answer

IOptions<T> is registered as a singleton, bound once on first use, and never changes. IOptionsSnapshot<T> is registered as scoped: it binds once per DI scope, which in ASP.NET Core means once per HTTP request, so it sees reloaded configuration and gives a consistent value for the whole request, at the cost of a bind per scope. Injecting it into a singleton is a captive-dependency error (scope validation throws in Development); if a singleton needs it, create a scope with IServiceScopeFactory, or more simply use the monitor. IOptionsMonitor<T> is a singleton that returns the latest value via CurrentValue (cached until the source reloads) and raises OnChange. For run-time changes, use IOptionsMonitor<T> in singletons and background services, and IOptionsSnapshot<T> in request-scoped code that needs one consistent value per request.

🔍 What the interviewer is checking

Checks they know the lifetimes and refresh behaviour of the options interfaces.

↩ Usually asked after

More in Cloud-Native Patterns

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me