Skip to content

Reactive, strongly-typed configuration layering for .NET

Cocoar.Configuration

License: Apache-2.0NuGetDownloads

Zero ceremony configuration that updates itself. Define a class, add a rule, inject it — no IOptions<T> wrappers, no Configure<T>() calls.

Install

dotnet add package Cocoar.Configuration # Core library (console apps)
dotnet add package Cocoar.Configuration.DI # + Microsoft.Extensions.DI
dotnet add package Cocoar.Configuration.AspNetCore # + health endpoints, feature flags

You only need one — each includes everything above it. Requires .NET 9+.

Optional provider packages add only the integration you need:

dotnet add package Cocoar.Configuration.ConfigHub # ConfigHub delivery and live invalidation
dotnet add package Cocoar.Configuration.Http # Generic remote configuration via HTTP

Quick Start

varbuilder=WebApplication.CreateBuilder(args);builder.AddCocoarConfiguration(c =>c.UseConfiguration(rule =>[rule.For<AppSettings>().FromFile("appsettings.json"),rule.For<AppSettings>().FromEnvironment("APP_"),]));varapp=builder.Build();// Inject directly — no wrapperapp.MapGet("/settings",(AppSettingssettings)=>new{settings.AppName,settings.MaxRetries});app.Run();

Key Features

  • Zero Ceremony — Define a class, add a rule, inject it. Just your POCO.
  • Reactive by DefaultIReactiveConfig<T> updates automatically when sources change.
  • Atomic UpdatesIReactiveConfig<(T1, T2)> guarantees consistent snapshots across types.
  • Explicit Layering — Rules execute in order, last write wins. File, environment, CLI, HTTP.
  • Memory-Safe SecretsSecret<T> with automatic zeroization and X.509 hybrid encryption.
  • Feature Flags & Entitlements — Strongly-typed, source-generated, with expiry health monitoring.
  • Multi-Tenant — The same config type resolves per tenant on a shared global base; .TenantScoped() rules, …ForTenant(id) access.
  • DI-Aware Providers — Opt-in Layer-2 rules whose providers use IHttpClientFactory / Marten / EF, without giving up the no-DI core.
  • Health Monitoring — Per-rule status tracking, OpenTelemetry metrics, ASP.NET Core health checks.
  • Compile-Time Validation — Roslyn analyzers catch configuration errors in your IDE.
  • First-Class TestingCocoarTestConfiguration with AsyncLocal<T> isolation.

Providers

ProviderFluent APIPackage
File (JSON).FromFile("path")Core
Environment Variables.FromEnvironment("PREFIX_")Core
Command Line.FromCommandLine("--prefix")Core
Static / Observable.FromStaticJson() / .FromObservable()Core
WritableStore (writable overlay).FromStore()Core
ConfigHub.FromConfigHub(url, token)ConfigHub
HTTP.FromHttp(url)Http
Microsoft IConfiguration.FromIConfiguration(config)MicrosoftAdapter

Examples

Explore real-world scenarios in the examples directory.

Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

License

Apache-2.0 — see NOTICE for details.

Releases

Packages

Contributors

Languages