Use Dynamic-Configuration to manage configurations and feature flags dynamically at runtime

Diginsight telemetry supports dynamic configuration to hot switch configuration values, based on http headers (or other information).
As an example, lets assume that a Web Application implements a concurrency option such as the following:

"AppSettings": {
  "MaxConcurrency": 10,
}

With diginsight, the developer can register such a configuration so that it can be overridden at runtime by means of the Dynamic-Configuration http request header, for specific calls.

The following paragraphs show how to reguster and use such a dynamic configuration.
The following code snippets can be found into the S01_00_SampleWebAPI project in Diginsight telemetry.samples repository.

Additional information

The snippet below, shows the ConcurrencyOptions class used for loading the MaxConcurrency settings.
A marker interface IDynamicallyConfigurable is used to mark the class as dynamically configurable.

public class ConcurrencyOptions : IDynamicallyConfigurable
{
    public int? MaxConcurrency { get; set; }
}

The developer can register the configuration within the startup sequence, as shown below:

services.ConfigureClassAware<ConcurrencyOptions>(configuration.GetSection("AppSettings"))
    .DynamicallyConfigureClassAware<ConcurrencyOptions>();

The image below shows the sample code where th concurrencyOptionsMonitor is injected into the constructor of the WeatherForecastController class and used into the Get() method.
alt text

In this way, ConcurrencyOptions options will be overridable by means of the Dynamic-Configuration http request header.

The image below shows a call to the S01_00_SampleWebAPI sample api where MaxConcurrency value 10 is loaded from the appSettings.json:

alt text

The output log below shows the MaxConcurrency value of 10 read from the appSettings.json configuration file: alt text

The image below shows a call to the S01_00_SampleWebAPI sample api where MaxConcurrency value is overridden to 1 by means of the Dynamic-Configuration http request header:

alt text

The output log below shows the MaxConcurrency value of 1 overridden by means of the Dynamic-Configuration http request header:

alt text
Back to top