⚙️ The Configuration Reload That Never Reached the Singleton
IOptionsSnapshot exists specifically to give you a fresh configuration value on every scoped lifetime – typically once per request – which makes it the obvious choice when you want config changes to apply without restarting the app. The catch is that IOptionsSnapshot is itself registered as a scoped service, and a singleton can only ever be constructed once, the very first time it’s requested. Injecting IOptionsSnapshot into a singleton’s constructor doesn’t make that singleton reload config on every request – it captures exactly one snapshot, taken at startup, and silently keeps using it for the lifetime of the application.
🔎 The Problem
public class FeatureGate
{
private readonly FeatureOptions _options;
// Looks like it will pick up live config changes...
public FeatureGate(IOptionsSnapshot<FeatureOptions> snapshot)
{
_options = snapshot.Value; // captured ONCE, at app startup,
// because FeatureGate is a singleton
}
public bool IsEnabled(string feature) => _options.Enabled.Contains(feature);
}
// Program.cs
builder.Services.Configure<FeatureOptions>(builder.Configuration.GetSection("Features"));
builder.Services.AddSingleton<FeatureGate>(); // the mismatch is here
// Editing appsettings.json afterward (even with reloadOnChange: true)
// never changes what FeatureGate.IsEnabled() returns again.
✅ Fix: Match the Options Interface to the Service’s Actual Lifetime
- Use plain IOptions in a singleton only when the value genuinely never needs to change after startup – it behaves exactly the same way IOptionsSnapshot does there, so there’s no benefit to the snapshot type in that spot.
- If a singleton genuinely needs to see live configuration changes, inject IOptionsMonitor instead, which is designed to work from any lifetime and exposes a CurrentValue property plus an OnChange callback for exactly this situation.
- Reserve IOptionsSnapshot for services registered as scoped or transient, where a fresh value per request is both possible and meaningful – injecting it into anything with a longer lifetime quietly defeats its entire purpose.
⚠️ Why This Is Easy to Miss
- The app starts up correctly, the first request reads the right value, and nothing throws – the only symptom is that a config change made later in production never takes effect, which looks like a deployment or caching problem, not a DI lifetime mismatch.
- The DI container doesn’t warn about this combination at all, since injecting a scoped service into a singleton is only a hard failure when scope validation is explicitly enabled – otherwise it builds and runs with no indication anything is wrong.
IOptionsSnapshot only refreshes as often as the thing holding it is recreated – and a singleton, by definition, never is.




