Cocoar.Configuration
0.9.0
See the version list below for details.
dotnet add package Cocoar.Configuration --version 0.9.0
NuGet\Install-Package Cocoar.Configuration -Version 0.9.0
<PackageReference Include="Cocoar.Configuration" Version="0.9.0" />
<PackageVersion Include="Cocoar.Configuration" Version="0.9.0" />
<PackageReference Include="Cocoar.Configuration" />
paket add Cocoar.Configuration --version 0.9.0
#r "nuget: Cocoar.Configuration, 0.9.0"
#:package Cocoar.Configuration@0.9.0
#addin nuget:?package=Cocoar.Configuration&version=0.9.0
#tool nuget:?package=Cocoar.Configuration&version=0.9.0
Cocoar.Configuration
Lightweight, strongly-typed, deterministic multi-source configuration layering for .NET (Current target framework: net9.0).
Why Cocoar.Configuration?
Deterministic, strongly-typed, rule-driven configuration layering that complements Microsoft.Extensions.Configuration
.
Design Goals at a Glance
- Explicit ordered layering: Deterministic last-write-wins per key.
- Typed direct injection: Inject config classes or mapped interfaces (no
IOptions<T>
ceremony). - Atomic snapshot recompute: Full ordered rebuild on change → consistent view for all consumers.
- Dynamic rule factories: Later rules can read earlier in-progress snapshots to shape options/queries.
- Pluggable provider model: File, environment, HTTP polling, Microsoft adapter, static & custom.
- DI lifetimes & keys: Configure singleton (default), scoped, transient, keyed variants per type.
- Per-type diagnostics: Inspect merged snapshots when troubleshooting.
- Interoperability: Bring any existing
IConfigurationSource
via the Microsoft Adapter package.
Installation
Supported TFM: net9.0 (multi-targeting planned).
<ItemGroup>
<PackageReference Include="Cocoar.Configuration" />
<PackageReference Include="Cocoar.Configuration.AspNetCore" />
<PackageReference Include="Cocoar.Configuration.HttpPolling" />
<PackageReference Include="Cocoar.Configuration.MicrosoftAdapter" />
</ItemGroup>
CLI:
dotnet add package Cocoar.Configuration
dotnet add package Cocoar.Configuration.AspNetCore
dotnet add package Cocoar.Configuration.HttpPolling
dotnet add package Cocoar.Configuration.MicrosoftAdapter
Quick Start
Minimal example (file + environment layering, strongly-typed access):
// ...
builder
.AddCocoarConfiguration(
Rule.From.File(_ => FileSourceRuleOptions.FromFilePath("appsettings.json", "App")).For<AppSettings>().Optional(),
Rule.From.Environment(_ => new EnvironmentVariableRuleOptions("APP_")).For<AppSettings>()
);
Then inject your config type directly:
var settings = app.Services.GetRequiredService<AppSettings>();
Console.WriteLine($"FeatureX: {settings.EnableFeatureX}");
Concepts
- Rule: Source + optional query + target configuration type
- Provider: Pluggable source (file, env, HTTP, static, custom, adapter)
- Merge: Ordered last-write-wins per flattened key
- Recompute: Any change → full recompute → atomic snapshot swap
- Dynamic dependencies: Rule factories (options/query) can read in-progress snapshots.
- Required vs Optional: Pptional failure skips the layer.
- DI Lifetimes & Keys: Register as singleton (default), scoped, transient, keyed
👉 Read more in the Concepts Deep Dive
Providers
Built-in and extension providers:
Provider | Package | Change Signal | Notes |
---|---|---|---|
Static | Core | ❌ | Seed defaults, compose values |
File (JSON) | Core | ✅ Filesystem watcher | Deterministic layering |
Environment | Core | ❌ | Prefix filter; __ & : nesting |
HTTP Polling | Extension | ✅ | Interval polling, payload diffing |
Microsoft Adapter | Extension | Depends | Any IConfigurationSource |
👉 See Providers Overview for full details.
Advanced Features
- Service Lifetimes & Keys: control DI lifetimes, keyed configs
- Generic Provider API:
Rule.From.Provider<>()
for full control - Microsoft Adapter: wrap any
IConfigurationSource
- HTTP Polling Provider: auto-change detection
👉 Details in Advanced Features
Security
- Never commit secrets to JSON files in your repository
- Use environment variable overlays or dedicated secret management systems
- For remote providers: Always use TLS, set reasonable timeouts, and include auth headers when needed
- Consider using Azure Key Vault, AWS Secrets Manager, or similar via the Microsoft Adapter
Examples
Multi-project solution under src/Examples/
with runnable demos:
- BasicUsage – File + environment layering pattern (full code)
- AspNetCoreExample – Web application integration
- FileLayering – Multiple JSON layers (deterministic last-write-wins)
- ServiceLifetimes – DI lifetimes + keyed registrations
- DynamicDependencies – Rules reading other config mid-recompute
- GenericProviderAPI – Full generic provider control
- MicrosoftAdapterExample – Integrate any
IConfigurationSource
- HttpPollingExample – Remote polling with change detection
- StaticProviderExample – Seeding & composition with static rules
Deep Dive Documentation
For more in-depth documentation, see:
- Architecture – execution & merge pipeline, change model
- Providers – static, file, env, HTTP, Microsoft adapter
- Concepts – rules, merge semantics, dependencies
- Examples – runnable samples
- Provider Development Guide – build your own provider
Thread Safety & Performance
- Reading config is thread-safe
- Recompute is O(n) per rules + JSON size
- Providers reused across recomputes when options stable
Versioning & Stability
- Stable releases follow SemVer; see GitHub Releases or NuGet version history for changes.
- Breaking changes only in MAJOR versions; MINOR for additive features; PATCH for fixes.
- Provider abstractions evolve conservatively.
Packages are published under the NuGet organization cocoar.
Contributing
Issues and PRs are welcome 🎉 Keep provider abstractions stable & deterministic. Examples and docs are validated in CI.
(This README reflects the current state – future optimizations & multi-targeting will be documented in docs/
.)
Product | Versions 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. |
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- System.Reactive (>= 6.0.1)
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.
Initial release: lightweight, strongly-typed, deterministic multi-source configuration layering with ordered last-write-wins merge and atomic recompute.