OnTheFlySettings 2.0.0

dotnet add package OnTheFlySettings --version 2.0.0
                    
NuGet\Install-Package OnTheFlySettings -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OnTheFlySettings" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OnTheFlySettings" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="OnTheFlySettings" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OnTheFlySettings --version 2.0.0
                    
#r "nuget: OnTheFlySettings, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OnTheFlySettings@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OnTheFlySettings&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=OnTheFlySettings&version=2.0.0
                    
Install as a Cake Tool

OnTheFlySettings

.NET Build & Test

Packages Version Downloads
OnTheFlySettings Nuget Version Downloads count
OnTheFlySettings.Client Nuget Version Downloads count
OnTheFlySettings.AzureKeyVault.Client Nuget Version Downloads count

Supports .NET 6/7/8/9/10.

On The Fly Settings

This project is a AspNetCore library that provides a way to update API/App settings on-the-fly.

Zero downtime! At runtime! No need to restart your API/App!

It supports various settings sources.

Plugging in the framework

You may keep your settings in your application's appsettings.json.

Create settings section

Create a section in your appsettings.json for the settings that you want to update on-the-fly:

{
  "MyHealthCheckBasicSettings": {
    "HealthCheckIntervalInMinutes": 15,
    "HealthCheckIntervalCronExpression": "* * * * *",
    "HealthCheckServerHubUrl": "https://localhost:5001/livehealthcheckshub",
    "PublishOnlyWhenNotHealthy": false,
    "AddHealthCheckMiddleware": false
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  }
}

Create settings class

Create a settings class called MyHealthCheckBasicSettings (for eg.) in your application:

public class MyHealthCheckBasicSettings
{
    public int HealthCheckIntervalInMinutes { get; set; }
    public string HealthCheckIntervalCronExpression { get; set; }
    public string HealthCheckServerHubUrl { get; set; }
    public bool PublishOnlyWhenNotHealthy { get; set; }
    public bool AddHealthCheckMiddleware { get; set; }
}

Configuring the library

Then you can configure the library in your Startup.cs or Program.cs file.

Bind the section to the settings class & add to OnTheFlySettings framework:

using OnTheFlySettings;
var builder = WebApplication.CreateBuilder(args);

builder.Configuration
       .SetBasePath(Directory.GetCurrentDirectory())
       .AddJsonFile("appsettings.json", false, true);

var appBasicSettings = builder.Configuration.GetSection("MyHealthCheckBasicSettings")
                                            .Get<MyHealthCheckBasicSettings>();

if (appBasicSettings == null)
    throw new ApplicationException("Settings not found.");

// Add the settings to the OnTheFlySettings framework
builder.Services.AddOnTheFlySettings(appBasicSettings);

Library provides Minimal API endpoints for reading and updating settings. Read more.

Add the endpoints to your application:

app.MapGetOnTheFlySettings()
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.							

app.MapPutReplaceOnTheFlySettings()
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.
							

Thats it!

Plugging in the Azure framework

You may keep your settings as secrets in the Azure Key Vault.

The Key Vault name can be anything you want.

Azure Secrets

In that case, you can do as shown below.

Create settings class

Create a settings class called MyHealthCheckBasicSettings (for eg.) in your application:

public class MyHealthCheckBasicSettings
{
    public int HealthCheckIntervalInMinutes { get; set; }
    public string HealthCheckIntervalCronExpression { get; set; }
    public string HealthCheckServerHubUrl { get; set; }
    public bool PublishOnlyWhenNotHealthy { get; set; }
    public bool AddHealthCheckMiddleware { get; set; }
}

Configuring the library

Then you can configure the library in your Startup.cs or Program.cs file.

Fetch the settings from Azure Key Vault & add to OnTheFlySettings framework:

using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using OnTheFlySettings;
var builder = WebApplication.CreateBuilder(args);

string keyVaultName = "ontheflysettings";
var kvUri = "https://" + keyVaultName + ".vault.azure.net";

var credential = new ClientSecretCredential("<<your tenantId here>>",
                                            "<<your clientId here>>",
                                            "<<your clientSecret here>>");

var client = new SecretClient(new Uri(kvUri), credential);

var appBasicSettings = new MyHealthCheckBasicSettings
{
    HealthCheckIntervalInMinutes = int.Parse((await client.GetSecretAsync("HealthCheckIntervalInMinutes")).Value.Value),
    HealthCheckIntervalCronExpression = (await client.GetSecretAsync("HealthCheckIntervalCronExpression")).Value.Value,
    HealthCheckServerHubUrl = (await client.GetSecretAsync("HealthCheckServerHubUrl")).Value.Value,
    PublishOnlyWhenNotHealthy = bool.Parse((await client.GetSecretAsync("PublishOnlyWhenNotHealthy")).Value.Value),
    AddHealthCheckMiddleware = bool.Parse((await client.GetSecretAsync("AddHealthCheckMiddleware")).Value.Value)
};

// Add the settings to the OnTheFlySettings framework
builder.Services.AddOnTheFlySettings(appBasicSettings);

Library provides Minimal API endpoints for reading and updating settings. Read more.

Add the endpoints to your application:

app.MapGetOnTheFlySettings()
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.

app.MapAzurePutReplaceOnTheFlySettings()
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.

Thats it!

Usage in your API/App

The library provides a IOnTheFlySettings<TSettings> interface that you use in your API/App.

IOnTheFlySettings

Events

The interface has an event OnSettingsChanged.

You can subscribe to the event in your own class, for example in a service class.

Just inject the IOnTheFlySettings<TSettings> interface into your class and subscribe to the event:

private readonly IOnTheFlySettings<MyHealthCheckBasicSettings> _settingsHolder;

// Constructor
public MyService(
                    IOnTheFlySettings<MyHealthCheckBasicSettings> settingsHolder
                )
{            
    _settingsHolder = settingsHolder;
    _settingsHolder.OnSettingsChanged += SettingsHolder_OnSettingsChanged;
}

private async Task SettingsHolder_OnSettingsChanged(MyHealthCheckBasicSettings? oldSettings, MyHealthCheckBasicSettings newSettings)
{
    // Handle the settings change event here
}

or

you can also subscribe to the event in your Startup.cs or Program.cs file:

var settingsHolder = app.Services.GetRequiredService<IOnTheFlySettings<MyHealthCheckBasicSettings>>();

settingsHolder.OnSettingsChanged += async (oldSettings, newSettings) =>
{
    // Handle the settings change event here
};

Accessing Current Settings

The interface has Current & Old properties to access the current & previous settings.

Using dependency injection

You can also use the interface to access the current settings at any time:

var basicSettings = _serviceProvider.GetRequiredService<IOnTheFlySettings<MyHealthCheckBasicSettings>>().Current;

or

via constructor injection in your class:

private readonly MyHealthCheckBasicSettings _basicSettings;

// Constructor
public MyService(
                    IOnTheFlySettings<MyHealthCheckBasicSettings> settingsHolder
                )
{            
    _basicSettings = settingsHolder.Current;
}
Using global variable

Create a static Globals class in your application.

public static class Globals
{
    public static MyHealthCheckBasicSettings? BasicSettings { get; set; }
}

Then, subscribe to OnSettingsChanged event in your Program.cs or Startup.cs.

Update the Globals property in the event handler.

var settingsHolder = app.Services.GetRequiredService<IOnTheFlySettings<MyHealthCheckBasicSettings>>();

settingsHolder.OnSettingsChanged += async (oldSettings, newSettings) =>
{
    lock(_lockObj)
    {
        Globals.BasicSettings = newSettings;
    }
};

Use Globals.BasicSettings in your code.

Endpoints - read/update settings on-the-fly

Library provides Minimal API endpoints for managing settings, including reading, and updating settings.

You can secure these endpoints using authentication and authorization mechanisms provided by ASP.NET Core.

To add the endpoints to your application, you can use the following code in your Startup.cs or Program.cs file:

app.MapGetOnTheFlySettings()
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.

app.MapPutReplaceOnTheFlySettings()
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.

app.MapAzurePutReplaceOnTheFlySettings()
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.

Default routes to the endpoints are:

  • GET /settings

  • PUT /settings/replace

  • PUT /settings/azure/replace

but you can customize the routes by providing your own route templates:

app.MapGetOnTheFlySettings("/my-custom-route")
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.

app.MapPutReplaceOnTheFlySettings("/my-custom-route/replace")
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.

app.MapAzurePutReplaceOnTheFlySettings("/my-custom-route/azure/replace")
   .RequireAuthorization(); // Provide your own authorization policy here
                            // or remove this line to allow anonymous access.

Get settings

Sample Screenshot

Replace settings

Sample Screenshot

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 94 9/28/2026
1.0.1 95 9/15/2026
1.0.0 89 9/14/2026

Support for settings as secrets in Azure Key Vault.