Hot Reload

Hot reload is a JsonConfigManager feature. EnvVarConfigManager has no equivalent, since a process’s environment block is fixed after start (see Environment Variables).

Enabling it

var configMgr = JsonConfigManager.BuildInstance("default")
    .EnableHotReload()
    .Register<AppSettings>("app-settings.json")
    .Build();

EnableHotReload() attaches a FileSystemWatcher on the instance’s directory (non-recursive), watching for changed, created, and renamed files.

What actually happens on a change

When the watcher fires for a file matching a registered type, that type’s cache entry is invalidated: not eagerly re-read, and the tracked version used by Put’s optimistic concurrency check is not advanced. The next Get<T>() call (no refresh: true needed) picks up the change lazily by reading and re-caching:

// external process (or a manual edit) changes app-settings.json on disk

AppSettings settings = configMgr.Get<AppSettings>(); // reflects the external change, no refresh needed

Invalidation only clears the cache entry; it doesn’t touch the tracked version Put’s optimistic concurrency check compares against. So a Get<T> made before the external change is still tied to the version from before that change:

AppSettings settings = configMgr.Get<AppSettings>(); // before the external change

// external process changes app-settings.json on disk

settings.TimeoutSeconds = 60;
configMgr.Put(settings); // false: rejected as stale, same as without hot reload

Put sees the file’s current version doesn’t match the one settings came from and rejects it, exactly as it would without hot reload enabled. Hot reload’s only effect here is on the next Get<T>(): instead of returning a stale cached object, it reads and re-caches the external change.

Multiple instances on the same directory

Independent instances (each with hot reload enabled and its own FileSystemWatcher) can point at the same directory and the same file without interfering. Each observes the change and invalidates its own cache independently.

Next steps

  • JSON Configuration: Get/Put and the optimistic concurrency check hot reload interacts with