Cocoar.Configuration 0.14.0

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

Cocoar.Configuration

Powerful layered configuration for .NET
Simple • Strongly typed • Reactive

Cocoar.Configuration

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


Why?

Most apps just need: "Give me my configs, layered, strongly typed, and keep them fresh."

Cocoar.Configuration lets you:

  • Define a few ordered rules → get ready-to-inject types
  • Layer file + env + http + static sources deterministically (last-write-wins per key)
  • Get push updates automatically via IReactiveConfig<T> (no extra setup)

If you need more later (interface binding, DI lifetime control, custom providers) it’s all there—opt‑in, not in your face.


Quick Start (Minimal ASP.NET Core)

appsettings.json:

{
  "App": {
    "FeatureFlag": true,
    "Message": "Hello from config"
  }
}

Program.cs:

var builder = WebApplication.CreateBuilder(args);

// Register layered configuration (file + environment overlay)
builder.Services.AddCocoarConfiguration([
    Rule.From.File("appsettings.json").Select("App").For<AppSettings>(),
    Rule.From.Environment("APP_").For<AppSettings>()
]);

var app = builder.Build();

// Simple endpoint: inject concrete snapshot (Scoped)
app.MapGet("/feature", (AppSettings cfg) => new {
    snapshotFlag = cfg.FeatureFlag,  // Value at scope start (request)
    message = cfg.Message
});

// Reactive usage example (background logging)
var reactive = app.Services.GetRequiredService<IReactiveConfig<AppSettings>>();
var _ = reactive.Subscribe(c => Console.WriteLine($"[Config Updated] FeatureFlag={c.FeatureFlag}"));

app.Run();

public sealed class AppSettings
{
    public bool FeatureFlag { get; set; }
    public string Message { get; set; } = string.Empty;
}

appsettings.json changed? — future requests see the updated snapshot; reactive stream subscribers get a push..


Reactive by Default

Every configuration type you map gets a free reactive companion:

You Have You Also Automatically Have
AppSettings IReactiveConfig<AppSettings>

IReactiveConfig<T> gives you:

  • CurrentValue – latest stable value
  • Subscribe(...) – push updates only when actual content changes
  • Safe & error-resilient stream: subscriber exceptions are logged, never terminate the pipeline

Guidance:

  • In request/short-lived scopes: inject the concrete type (AppSettings) for a consistent snapshot
  • In background services / singletons: inject IReactiveConfig<T>
  • Need a frozen value inside a singleton? Capture live.CurrentValue once (rarely required)

Rule Basics

A rule = provider + (optional selection/query) + target config type. Order matters: later rules overwrite earlier values per flattened key (deterministic last-write-wins).

var rules = new [] {
    Rule.From.File("appsettings.json").For<AppSettings>(),
    Rule.From.Environment("APP_").For<AppSettings>()
};

Additional options (add only when needed):

Rule.From.File("secrets.json")
    .Select("Secrets:Db")        // select subtree
    .Mount("Database")           // mount under a new path
    .Required()                  // fail the rule if source missing
    .For<DatabaseConfig>();

Interface Binding (Optional)

Start without it. Add when you want to inject contracts instead of concretes.

services.AddCocoarConfiguration(rules, [
    Bind.Type<AppSettings>().To<IAppSettings>()
]);

public sealed class Handler(IAppSettings cfg, IReactiveConfig<IAppSettings> live)
{ /* ... */ }

More patterns: BINDING.md.


DI Lifetimes & Defaults

By default:

  • Concrete config types: Scoped (one snapshot per request/scope)
  • IReactiveConfig<T>: Singleton (continuous live updates)

Change the default lifetime:

services.AddCocoarConfiguration(rules, configureServices: o =>
    o.DefaultRegistrationLifetime(ServiceLifetime.Singleton));

Disable auto reactive registration (rare):

o.DisableAutoReactiveRegistration();

Manual overrides & keyed registrations: see ADVANCED.md.

Choosing a Lifetime: | Scenario | Lifetime | |----------|----------| | Typical web request consumption | Scoped | | High-read immutable small config | Singleton | | Background service (reactive) | Scoped + IReactiveConfig<T> (preferred) | | Large object, avoid mid-request drift | Scoped |


Providers (Built-In & Extensions)

Provider Package Change Signal Notes
Static Core JSON strings or factories
File (JSON) Core ✅ FS watcher Deterministic layering
Environment Core Prefix filter; __ / : nesting
HTTP Polling Extension ✅ Interval polling Payload diffing (streaming hash)
Microsoft Adapter Extension Depends Any IConfigurationSource

Detailed provider docs: PROVIDERS.md.


Performance & Reliability (Short Version)

  • Atomic recompute + full snapshot publish
  • Incremental: recompute only from earliest changed rule
  • Streaming JSON → MD5 hashing (no intermediate string allocations)
  • Hash-gated reactive emissions (no duplicate pushes)
  • Error-resilient reactive pipelines (no dead observables)
  • 80+ tests (stress, cancellation, differential correctness)

Deep dive: ARCHITECTURE.md, CONCEPTS.md.


When You Need More

Need Go To
Interface patterns docs/BINDING.md
Advanced DI control docs/ADVANCED.md
Architecture & pipeline docs/ARCHITECTURE.md
Providers overview docs/PROVIDERS.md
Migration notes docs/MIGRATION.md
Build your own provider docs/PROVIDER_DEV.md
Deep scenarios (lifecycle, dynamic factories, tuning) docs/DEEP_DIVE.md

Installation

<ItemGroup>
  <PackageReference Include="Cocoar.Configuration" />
  <PackageReference Include="Cocoar.Configuration.DI" />
  
  <PackageReference Include="Cocoar.Configuration.HttpPolling" />
  <PackageReference Include="Cocoar.Configuration.MicrosoftAdapter" />
  <PackageReference Include="Cocoar.Configuration.AspNetCore" />
</ItemGroup>

CLI:

dotnet add package Cocoar.Configuration
dotnet add package Cocoar.Configuration.DI

(Add extensions only when needed.)


Examples

Each example is a standalone runnable project under src/Examples/:

Project Description
BasicUsage Common ASP.NET Core pattern (file + env overlay)
FileLayering Multiple JSON layering (base + env + local)
DynamicDependencies Later rules derive values from earlier configs
AspNetCoreExample Minimal API exposing config via endpoints
GenericProviderAPI Generic provider registration API usage
HttpPollingExample Remote HTTP polling configuration pattern
MicrosoftAdapterExample Integrating existing IConfigurationSource assets
ServiceLifetimes DI lifetime & keyed registration control
StaticProviderExample Static seeding with JSON strings and factory functions
DIExample Comprehensive DI patterns & overrides
SimplifiedCoreExample Pure core (no DI) with ConfigManager
BindingExample Interface binding without DI

More details: Examples README.


Security Notes

  • Do not commit secrets to repo JSON
  • Overlay secrets via env/provider layers
  • Use TLS + auth for remote polling
  • Consider vault integration via Microsoft adapter

Contributing & Versioning

  • SemVer (additive MINOR, breaking MAJOR)
  • PRs & issues welcome
  • Licensed under Apache License 2.0 (explicit patent grant & attribution via 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. Use of the name in forks or derivatives should preserve attribution and avoid implying official endorsement. See TRADEMARKS for permitted and restricted uses.


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 (4)

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

Package Downloads
Cocoar.Configuration.AspNetCore

Powerful layered configuration for .NET—simple, strongly typed, reactive. Compose ordered rules (file, environment, HTTP polling, static, Microsoft IConfiguration) with deterministic last-write-wins merging, partial atomic recompute, and hash-gated reactive streams.

Cocoar.Configuration.HttpPolling

Powerful layered configuration for .NET—simple, strongly typed, reactive. Compose ordered rules (file, environment, HTTP polling, static, Microsoft IConfiguration) with deterministic last-write-wins merging, partial atomic recompute, and hash-gated reactive streams.

Cocoar.Configuration.MicrosoftAdapter

Powerful layered configuration for .NET—simple, strongly typed, reactive. Compose ordered rules (file, environment, HTTP polling, static, Microsoft IConfiguration) with deterministic last-write-wins merging, partial atomic recompute, and hash-gated reactive streams.

Cocoar.Configuration.DI

Powerful layered configuration for .NET—simple, strongly typed, reactive. Compose ordered rules (file, environment, HTTP polling, static, Microsoft IConfiguration) with deterministic last-write-wins merging, partial atomic recompute, and hash-gated reactive streams.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.14.0 21 9/17/2025
0.13.0 34 9/17/2025
0.12.0 39 9/17/2025
0.11.1 45 9/16/2025
0.11.0 43 9/16/2025
0.10.0 48 9/16/2025
0.9.2 31 9/15/2025
0.9.1 27 9/14/2025
0.9.0 27 9/14/2025
0.4.0 29 9/13/2025