Advertisement
Advanced ASP.NET Core, Configuration & Options Pattern

How does configuration hot-reload work with reloadOnChange for appsettings.json, and what are its limitations?

Short answer

When appsettings.json is registered with reloadOnChange: true (the default), a file system watcher detects file changes and triggers IConfiguration to reload its values in-memory without an application restart -- code using IOptionsSnapshot or IOptionsMonitor automatically picks…

Save ASP.NET Core mock interview
Advertisement
AModel answer
When appsettings.json is registered with reloadOnChange: true (the default), a file system watcher detects file changes and triggers IConfiguration to reload its values in-memory without an application restart -- code using IOptionsSnapshot<T> or IOptionsMonitor<T> automatically picks up new values, but IOptions<T> (computed once, cached forever as a singleton) does not.
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

// A service using IOptionsMonitor sees updated values automatically:
public MyService(IOptionsMonitor<FeatureSettings> monitor) {
    monitor.OnChange(settings => _logger.LogInformation("Config reloaded"));
}
Real-world example
An ops team updates a feature toggle percentage directly in a mounted ConfigMap-backed appsettings.json file in a running Kubernetes pod, and the application picks up the change within seconds via hot-reload, without needing to restart the pod.
Likely follow-ups
  • Why doesn't IOptions<T> reflect hot-reloaded changes?
  • What are the risks of enabling hot-reload for security-sensitive settings?
Related topics