ConfigManager.Provider 2.0.0

dotnet add package ConfigManager.Provider --version 2.0.0
                    
NuGet\Install-Package ConfigManager.Provider -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="ConfigManager.Provider" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConfigManager.Provider" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ConfigManager.Provider" />
                    
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 ConfigManager.Provider --version 2.0.0
                    
#r "nuget: ConfigManager.Provider, 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 ConfigManager.Provider@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=ConfigManager.Provider&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ConfigManager.Provider&version=2.0.0
                    
Install as a Cake Tool

ConfigManager.Provider

A .NET Configuration Provider that enables dynamic configuration management with real-time updates from Redis.

NuGet Downloads

Features

  • Seamless Integration: Works with standard .NET IConfiguration
  • Real-time Updates: Configuration changes trigger automatic reloads
  • Project Isolation: Multi-project support with key prefixing
  • Performance Optimized: Efficient Redis operations with pub/sub
  • Production Ready: Robust error handling and connection management

Quick Start

1. Install Package

# Install the latest stable version
dotnet add package ConfigManager.Provider

# Or install specific version
dotnet add package ConfigManager.Provider --version 1.0.0

2. Basic Usage

using ConfigManager.Provider;

var configuration = new ConfigurationBuilder()
    .AddRedis("myapp", "localhost:6379")
    .Build();

// Read configuration
var dbHost = configuration["database:host"];
var logLevel = configuration["logging:level"];

3. With ASP.NET Core / Generic Host

var host = Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((context, config) =>
    {
        config.AddRedis(
            projectName: "myapp",
            connectionString: "localhost:6379",
            optional: true
        );
    })
    .Build();

4. Real-time Configuration Updates

// Monitor configuration changes
ChangeToken.OnChange(configuration.GetReloadToken, () =>
{
    Console.WriteLine("Configuration updated!");
});

Configuration Key Format

Redis keys follow the pattern: {projectName}:{group}:{setting}

Examples:

  • myapp:database:hostconfiguration["database:host"]
  • myapp:logging:levelconfiguration["logging:level"]
  • myapp:api:timeoutconfiguration["api:timeout"]

Advanced Configuration

config.AddRedis(source =>
{
    source.ProjectName = "myapp";
    source.ConnectionString = "localhost:6379";
    source.Database = 0;
    source.Optional = false; // Fail if Redis unavailable
    source.ReconnectInterval = TimeSpan.FromSeconds(30);
});

End-to-End Example: Real-Time Weather App

This complete example demonstrates the ConfigManager system working together. Based on our tested ConfigManager.ExampleApp.

Step 1: ASP.NET Core Application Setup

using ConfigManager.Provider;

var builder = WebApplication.CreateBuilder(args);

// Add Redis configuration provider
builder.Configuration.AddRedis(
    projectName: "exampleapp",
    connectionString: "your-redis-server:6379",
    optional: true  // Don't fail if Redis is unavailable
);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configuration demo endpoints
app.MapGet("/config", (IConfiguration config) =>
{
    var allConfig = new Dictionary<string, string?>();
    foreach (var kvp in config.AsEnumerable())
    {
        if (!string.IsNullOrEmpty(kvp.Value))
        {
            allConfig[kvp.Key] = kvp.Value;
        }
    }
    return Results.Json(allConfig);
});

app.MapGet("/weatherforecast", (IConfiguration config) =>
{
    // Use configuration for real-time weather customization
    var location = config["weather:location"] ?? "Unknown";
    var maxTemp = config.GetValue<int>("weather:maxTemp", 55);
    var minTemp = config.GetValue<int>("weather:minTemp", -20);
    
    var forecast = Enumerable.Range(1, 5).Select(index =>
        new WeatherForecast
        (
            DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
            Random.Shared.Next(minTemp, maxTemp),
            summaries[Random.Shared.Next(summaries.Length)],
            location
        ))
        .ToArray();
    return forecast;
});

app.Run();

record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary, string Location);

Step 2: Dynamic Configuration via ConfigManager.Web API

# Set weather location (instantly updates the app)
curl -X POST http://localhost:3001/redis/exampleapp:weather:location \
  -H "Content-Type: application/json" \
  -d '{"value": "San Francisco"}'

# Set temperature range
curl -X POST http://localhost:3001/redis/exampleapp:weather:maxTemp \
  -H "Content-Type: application/json" \
  -d '{"value": "25"}'

curl -X POST http://localhost:3001/redis/exampleapp:weather:minTemp \
  -H "Content-Type: application/json" \
  -d '{"value": "10"}'

Step 3: Verify Real-Time Updates

# Check current configuration
curl http://localhost:5000/config

# Get weather forecast with new location/temps
curl http://localhost:5000/weatherforecast

Result: The app immediately reflects the new configuration without restart!

[
  {
    "date": "2024-12-20",
    "temperatureC": 18,
    "summary": "Mild",
    "location": "San Francisco"
  }
]

Step 4: Live Configuration Changes

# Change location to Tokyo (takes effect in <100ms)
curl -X POST http://localhost:3001/redis/exampleapp:weather:location \
  -H "Content-Type: application/json" \
  -d '{"value": "Tokyo"}'

# Immediately check weather - location updated!
curl http://localhost:5000/weatherforecast

Integration with ConfigManager.Web

This provider works seamlessly with the ConfigManager.Web API:

  1. Set Configuration via API endpoint
  2. Configuration Auto-Updates in your .NET app via Redis pub/sub
  3. Project Discovery via /projects endpoint
  4. Automatic Project Registration when first configuration is set

Example: Complete Integration

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        var configuration = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .AddRedis("myapp", "redis://your-redis-server:6379")
            .Build();

        services.AddSingleton<IConfiguration>(configuration);
        
        // Use configuration in your services
        services.Configure<DatabaseOptions>(configuration.GetSection("database"));
        services.Configure<LoggingOptions>(configuration.GetSection("logging"));
    }
}

public class DatabaseOptions
{
    public string Host { get; set; } = "localhost";
    public int Port { get; set; } = 5432;
    public string ConnectionString => $"Host={Host};Port={Port}";
}

Error Handling

  • Optional Mode: Set optional: true to gracefully handle Redis unavailability
  • Connection Retry: Automatic reconnection with configurable intervals
  • Graceful Degradation: Falls back to default values when Redis is unavailable

Repository Structure

ConfigManager.Provider/
├── src/
│   ├── ConfigManager.Provider/          # Main NuGet package
│   └── ConfigManager.ExampleApp/        # Example ASP.NET Core app
├── tests/                               # Unit and integration tests
├── ConfigManager.Provider.sln          # Solution file
└── README.md                           # This file

Building and Testing

# Build the entire solution
dotnet build

# Run the example app
dotnet run --project src/ConfigManager.ExampleApp

# Run tests (when available)
dotnet test

# Pack for local testing
dotnet pack src/ConfigManager.Provider

Performance

  • O(1) Project Discovery: Uses Redis Sets for efficient project lookups
  • Minimal Memory: Only loads configuration for specified project
  • Pub/Sub Efficiency: Only subscribes to relevant configuration changes
  • Connection Pooling: Reuses Redis connections for optimal performance

License

MIT License - see LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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.

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 193 9/23/2025
1.0.1 231 9/19/2025
1.0.0 219 9/19/2025