Refresh Options at Runtime¶
Forge services refresh configuration from Azure App Configuration and Key Vault while they run, but only code that reads configuration at use time sees the new values. If a value changes in App Configuration or a secret rotates in Key Vault and your service keeps the old value until a restart, the cause is almost always how the code reads its options, not the platform.
This page covers values that can change while the service runs. Settings and Secrets covers where settings live. In a deployed service, values in appsettings.{env}.json change only when you deploy a new build. Local runs reload that file when it changes.
🧭 Read Options at Use Time¶
- Avoid
IOptions<T>for values that can change. It caches its first value for the life of the process. - Use
IOptionsSnapshot<T>in scoped services andIOptionsMonitor<T>in singletons. A singleton cannot takeIOptionsSnapshot<T>, and holding one captured from a scope freezes its value. - Do not cache derived objects. An
HttpClientdefault authorization header, an SDK client, or a token built once from options keeps the old values. Read the current value when you use it, or rebuild the object when options change. - Do not copy values into fields at startup. The same staleness applies to anything you copy out of
IConfigurationonce.
Microsoft documents the interfaces, lifetimes, and change notifications in Options pattern in ASP.NET Core and Enable dynamic configuration in ASP.NET Core.
🔌 Platform Wiring¶
The golden-path ASP.NET API templates call AddAzureDefaults() and UseAzureDefaults(), and the platform supplies AppConfigurationEndpoint to deployed services, so those services refresh without extra setup. Other host types, such as Functions, need their own check that refresh is wired. Bind your options to keys under a prefix the service loads. The SAIF.Platform.Azure README documents the wiring behavior.
For endpoints of other Forge services, use service discovery instead of a base URL in your own options. See Calling APIs. If a deployed caller reports Name or service not known (<projectId>:443), see the service-discovery troubleshooting article for refresh-wiring and downstream-deployment checks.
⚖️ What to Expect¶
- Refresh polls, it does not push. Changes reach the service after the refresh interval, never instantly.
- Requests trigger refresh. An idle service does not check for changes, and the request that triggers a check can still see the old value.
- Key Vault secrets refresh on their own interval. Forge writes versionless Key Vault references, so a rotated secret reaches the service on the secret refresh interval, not through change-based refresh. The service identity needs read access to the vault (Key Vault references).
- A bad value can fail after startup.
ValidateOnStart()only checks the values present at startup. Validators also run when options reload, and a value that fails can make later reads throw, so validate values before you change them in App Configuration or Key Vault. - Some values still need a restart: one-time startup decisions, connection strings and endpoints captured at startup, and singletons that copy options once.
🩺 Troubleshooting Checklist¶
Symptom: a value changed in App Configuration or Key Vault, but the service still uses the old value.
- Search the code for
IOptions<T>, values copied into fields, and clients or headers built once. Switch toIOptionsSnapshot<T>orIOptionsMonitor<T>. - Confirm
Program.cscalls bothAddAzureDefaults()andUseAzureDefaults(). - Confirm the key sits under a loaded prefix and carries no label or the environment label.
- Wait past the refresh interval, then send requests.
- For a Key Vault secret, confirm the App Configuration entry is a Key Vault reference and the service identity can read the vault.
- Turn on
Debuglogging forMicrosoft.Extensions.Configuration.AzureAppConfiguration.Refreshto see refresh activity and failures.