Interview frequency: …
Short answer
IOptions is a fixed Singleton, IOptionsSnapshot is recomputed for each HTTP request to support live updates, and IOptionsMonitor is a Singleton that receives file-change notifications without a request context.
Explanation
The Options Pattern strongly binds appsettings.json to plain C# classes. IOptions is lightweight but does not read changes made after startup. IOptionsSnapshot is for Scoped services and reads changes for each new request. IOptionsMonitor is used in Singleton services and background tasks (BackgroundServices), and raises OnChange when the file changes.
Code example
// Register
builder.Services.Configure<PaymentOptions>(builder.Configuration.GetSection("Payment"));
// Use in the service
public class PaymentService(IOptionsSnapshot<PaymentOptions> options) {
private readonly PaymentOptions _options = options.Value;
}Common mistakes
- Injecting IOptionsSnapshot into a Singleton service, causing a Dependency Injection lifetime mismatch error.