Cocoar.Configuration 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Cocoar.Configuration --version 3.0.0
                    
NuGet\Install-Package Cocoar.Configuration -Version 3.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="Cocoar.Configuration" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cocoar.Configuration" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Cocoar.Configuration" />
                    
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 Cocoar.Configuration --version 3.0.0
                    
#r "nuget: Cocoar.Configuration, 3.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 Cocoar.Configuration@3.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=Cocoar.Configuration&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Cocoar.Configuration&version=3.0.0
                    
Install as a Cake Tool

Reactive, strongly-typed configuration layering for .NET

Cocoar.Configuration

Elevates configuration from hidden infrastructure to an observable, safety‑enforced subsystem you can trust under change and failure.

Build (develop) PR Validation License: Apache-2.0 NuGet Downloads


Features

Key Capabilities

  • Automatic Reactive Configs – Every configured concrete type provides IReactiveConfig<T> (no opt-in).
  • Tuple Reactive SnapshotsIReactiveConfig<(T1,T2,...,TN)> for atomic aligned multi-config state (any tuple arity) with strict validation.
  • Health Monitoring Service – Real-time provider & rule health snapshots, status streams, metrics hook (see docs/health-monitoring.md).
  • Streaming MD5 Change Detection – Efficient hashing for file & HTTP providers.

Core Principles

  • Deterministic Layering – Ordered rules, last-write-wins, no hidden merge magic.
  • Strongly Typed – Direct POCO access (no IOptions<T> ceremony).
  • Atomic Snapshots – Always consistent; no partial updates.
  • Reactive & Dynamic – Change propagation with debounce + coalescing.

Rule System

  • Unified Fluent API across providers.
  • Composable Pipeline: Fetch → Select → Mount → Merge.
  • Dynamic Rule Factories – Derive new rules from earlier snapshot state.
  • Interface Exposure – Expose implemented interfaces for DI consumption.
  • Partial Recomputation – Only earliest changed rule re-executes.
  • Required / Optional Rules – Control startup fail vs graceful degradation.
  • Conditional Execution – Enable rules only when predicates hold.

Providers

  • Static / Observable (in-memory) built-ins.
  • File – Watch + resilient poll fallback & recovery.
  • Environment__ / : hierarchy mapping.
  • HTTP – Caching, headers, change-only emissions.
  • Microsoft Adapter – Bridge existing IConfiguration (extension package).

Health Monitoring & Reliability

  • Integrated IConfigurationHealthService.
  • Status & snapshot streams (coalesced, no duplicates).
  • Two‑phase error handling: fail-fast init, graceful runtime.
  • Last-known-good retention on provider failures.

Developer Experience (Simplified)

  • Minimal Boilerplate – Define class + rule; optionally expose interfaces.
  • Always ReactiveIReactiveConfig<T> & tuple variants auto available.
  • Scoped by Default – Concrete & exposed interfaces registered as Scoped.
  • Opt-Out.DisableAutoRegistration() (concrete) or global setup.ExposedType<IMy>().DisableAutoRegistration().
  • Atomic Tuple Snapshots – Any tuple shape; aligned updates only.
  • Test-Friendly – Deterministic providers; easy fake sources.
  • Clean Migration Path – Legacy Bind API replaced by Configure (see migration doc).

Install

dotnet add package Cocoar.Configuration
# For ASP.NET Core integration:
dotnet add package Cocoar.Configuration.AspNetCore

Quickstart

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCocoarConfiguration(rule => [
    rule.For<AppSettings>().FromFile("appsettings.json").Select("App"),
    rule.For<AppSettings>().FromEnvironment("APP_")
], setup => [
    setup.ConcreteType<AppSettings>()
        .ExposeAs<IAppSettings>() // optional interface exposure
]);

var app = builder.Build();

// Interface injection (Scoped)
app.MapGet("/feature", (IAppSettings cfg) => new { cfg.FeatureFlag, cfg.Message });

// Reactive tuple injection
app.MapGet("/composite", (IReactiveConfig<(AppSettings App, LoggingConfig Log)> composite) =>
{
    var (appCfg, log) = composite.CurrentValue;
    return new { appCfg.Version, log.Level };
});

app.Run();

Opt-Out Examples

// Inside your configure function:
builder.AddCocoarConfiguration(rule => [
    rule.For<AppSettings>().FromFile("appsettings.json")
], setup => [
    // Skip concrete registration
    setup.ConcreteType<AppSettings>().DisableAutoRegistration(),
    
    // Globally suppress interface registration (affects any future exposure of IAppSettings)
    setup.ExposedType<IAppSettings>().DisableAutoRegistration()
]);

Advanced Features

Conditional Rules with Config Awareness

The When() method now supports config-aware predicates using IConfigurationAccessor:

builder.Services.AddCocoarConfiguration(rule => [
    // Load tenant info first
    rule.For<TenantSettings>().FromFile("tenant.json"),
    
    // Conditionally load premium features based on tenant tier
    rule.For<PremiumFeatures>().FromFile("premium-features.json")
        .When(accessor =>
        {
            var tenant = accessor.GetRequiredConfig<TenantSettings>();
            return tenant.Tier == "Premium";
        }),
    
    // Conditionally load based on environment variable
    rule.For<DebugSettings>().FromFile("debug-settings.json")
        .When(_ => Environment.GetEnvironmentVariable("DEBUG_MODE") == "true")
]);

The predicate is evaluated during initialization and on every recompute—if it returns false, the rule is skipped entirely. This works seamlessly with dynamic rules for powerful conditional logic.


Examples

Project Description
BasicUsage ASP.NET Core + file + environment overlay
FileLayering Multi-file layering (base/env/local)
DynamicDependencies Rules derived from earlier snapshots
ConditionalRulesExample Config-aware conditional rule execution with When()
AspNetCoreExample Minimal API endpoints exposing config
GenericProviderAPI Using generic provider registration APIs
HttpPollingExample Remote HTTP polling pattern
MicrosoftAdapterExample Integrate existing IConfigurationSource providers
StaticProviderExample Static seeding with JSON / factories
SimplifiedCoreExample Pure core (no DI) usage
BindingExample Interface exposure without DI container
TupleReactiveExample Tuple-based aligned reactive snapshots

More: Examples README.


Quality & Reliability

Extensive automated test suite (>200 tests) spanning:

  • Integration & recompute pipeline
  • Concurrency, cancellation & debounce correctness
  • Large JSON + high-frequency mutation stress
  • File watcher ↔ polling resilience & recovery
  • HTTP provider headers, caching, status handling
  • Environment & adapter edge cases
  • Tuple reactive alignment correctness
  • Health snapshot/state transitions

See the Testing Guide for details.


Security Notes

  • Don’t commit secrets; overlay via environment / secure providers.
  • Use TLS + auth for remote polling.
  • Consider vault integration through the Microsoft adapter.

Contributing & Versioning

  • Semantic Versioning (breaking changes = MAJOR)
  • Issues & PRs welcome
  • Licensed under Apache 2.0 (see LICENSE, NOTICE)

License & Trademark

This project is licensed under the Apache License, Version 2.0. See NOTICE for attribution.

“Cocoar” and related marks are trademarks of COCOAR e.U. Usage in forks should preserve attribution and avoid implying endorsement. See TRADEMARKS.


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

Showing the top 5 NuGet packages that depend on Cocoar.Configuration:

Package Downloads
Cocoar.Configuration.AspNetCore

ASP.NET Core integration for Cocoar.Configuration providing health check endpoints, configuration health monitoring, and seamless integration with WebApplicationBuilder for reactive configuration in web applications.

Cocoar.Configuration.HttpPolling

HTTP polling provider for Cocoar.Configuration enabling remote configuration sources with configurable polling intervals, automatic retries, and failure sentinel values for resilient distributed configuration management.

Cocoar.Configuration.MicrosoftAdapter

Adapter for bridging Microsoft.Extensions.Configuration (IConfiguration) with Cocoar.Configuration, enabling gradual migration and coexistence with existing Microsoft configuration sources while leveraging reactive updates.

Cocoar.Configuration.DI

Dependency injection integration for Cocoar.Configuration with Microsoft.Extensions.DependencyInjection. Fluent API for registering configuration types with customizable lifetimes (singleton, scoped, transient) and keyed services.

Cocoar.Configuration.Secrets

Secure secrets management for Cocoar.Configuration using hybrid RSA+AES encryption. Store encrypted secrets directly in JSON configuration files with X.509 certificate-based decryption and automatic memory zeroing.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.4.0-secrets.36 180 11/16/2025
3.4.0-secrets.34 177 11/16/2025
3.4.0-secrets.32 100 11/15/2025
3.4.0-secrets.30 108 11/15/2025
3.4.0-secrets.29 109 11/15/2025
3.4.0-secrets.28 116 11/15/2025
3.4.0-secrets.27 121 11/15/2025
3.4.0-secrets.26 110 11/15/2025
3.4.0-secrets.25 159 11/14/2025
3.4.0-secrets.1 185 11/14/2025
3.4.0-beta.6 223 11/16/2025
3.3.0 173 10/23/2025
3.2.0 161 10/23/2025
3.1.1 170 10/19/2025
3.1.0 159 10/19/2025
3.0.0 171 10/12/2025
2.0.0 105 10/11/2025
1.1.0 228 9/25/2025
1.0.0 262 9/21/2025
0.15.0 340 9/18/2025
0.14.0 348 9/17/2025
0.13.0 356 9/17/2025
0.12.0 351 9/17/2025
0.11.1 343 9/16/2025
0.11.0 350 9/16/2025
0.10.0 340 9/16/2025
0.9.2 291 9/15/2025
0.9.1 262 9/14/2025
0.9.0 195 9/14/2025
0.4.0 188 9/13/2025