Differences between IOptions and IOptionsSnapshot interfaces and when to use which

What are the differences between IOptions and IOptionsSnapshot?

IOptions and IOptionsSnapshot are interfaces provided as a part of the IOptions framework provided in ASP.NET Core.

There are three interfaces provided by this namespace as a part of configuring IOptions instances:

  • IOptions
  • IOptionsSnapshot and
  • IOptionsMonitor

IOptions

  1. Options configured in IOptions are registered as SingletonServices
  2. Can be injected into any service for accessing options
  3. Doesn’t support option updates when configuration changes
  4. Doesn’t support Named options

IOptionsSnapshot

  1. Options configured in IOptionsSnapshot are registered as ScopedServices
  2. Can be injected into only Scoped and Transient services
  3. Supports updated options even after configuration is loaded
  4. Supports Named options

--

--

Sriram Kumar Mannava
Sriram Kumar Mannava

Written by Sriram Kumar Mannava

I make Full Stack Development Easy for You | Full Stack .NET Dev | 3× AWS Certified | Blogger