Baubit.Configuration 2025.49.1

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

Baubit.Configuration

CircleCI codecov<br/> NuGet .NET Standard 2.0<br/> License: MIT Known Vulnerabilities

Type-safe configuration builder for .NET with Result pattern error handling and environment variable expansion.

Features

  • Type-Safe - Bind configuration to strongly-typed classes
  • Result Pattern - Explicit error handling without exceptions
  • Environment Variable Expansion - ${VAR} syntax in configuration values
  • Multiple Sources - JSON files, embedded resources, raw strings, user secrets
  • Validation - Custom validator pipeline support
  • Fluent API - Chainable configuration methods

Installation

dotnet add package Baubit.Configuration

Quick Start

Basic Configuration

using Baubit.Configuration;

var result = ConfigurationBuilder.CreateNew()
    .Bind(b => b.WithRawJsonStrings("{\"Database\":\"Server=localhost\"}"))
    .Bind(b => b.Build());

if (result.IsSuccess)
{
    var value = result.Value["Database"]; // "Server=localhost"
}

Type-Safe Configuration

public class AppConfig : AConfiguration
{
    public string ConnectionString { get; init; }
    public int MaxRetries { get; init; }
}

var builder = ConfigurationBuilder<AppConfig>.CreateNew();
builder.WithRawJsonStrings("{\"ConnectionString\":\"...\",\"MaxRetries\":3}");
var result = builder.Build();

if (result.IsSuccess)
{
    var config = result.Value;
    Console.WriteLine(config.ConnectionString);
}

Environment Variable Expansion

public class PathConfig : AConfiguration
{
    [URI]
    public string LogPath { get; init; }
}

// With LogPath = "${HOME}/logs" in JSON
// Automatically expands to "/home/user/logs"
var builder = ConfigurationBuilder<PathConfig>.CreateNew();
builder.WithRawJsonStrings("{\"LogPath\":\"${HOME}/logs\"}");
var result = builder.Build();

Multiple Configuration Sources

var result = ConfigurationBuilder.CreateNew()
    .Bind(b => b.WithJsonUriStrings("file:///app/config.json"))
    .Bind(b => b.WithEmbeddedJsonResources("MyApp;Config.appsettings.json"))
    .Bind(b => b.WithLocalSecrets("MyApp-Secrets"))
    .Bind(b => b.WithRawJsonStrings("{\"Override\":\"Value\"}"))
    .Bind(b => b.Build());

Validation

using Baubit.Configuration.Validation;

public class AppConfigValidator : AValidator<AppConfig>
{
    public override Result Run(AppConfig config)
    {
        return Result.OkIf(
            config.MaxRetries > 0, 
            "MaxRetries must be positive"
        );
    }
}

var builder = ConfigurationBuilder<AppConfig>.CreateNew();
builder.WithRawJsonStrings("{\"ConnectionString\":\"test\",\"MaxRetries\":3}");
builder.WithValidators(new AppConfigValidator());
var result = builder.Build();

Configuration Sources

Source Method Format
JSON Files WithJsonUriStrings("file:///path") File URIs
Embedded Resources WithEmbeddedJsonResources("Assembly;Path") Assembly;Resource
Raw JSON WithRawJsonStrings("{...}") JSON strings
User Secrets WithLocalSecrets("SecretId") Secret ID
Additional Config WithAdditionalConfigurations(config) IConfiguration
Configuration Sources WithAdditionalConfigurationSourcesFrom(config) IConfiguration with "configurationSource" section
Configuration Data WithAdditionalConfigurationsFrom(config) IConfiguration with "configuration" section
Pre-built Sources WithAdditionalConfigurationSources(sources) ConfigurationSource objects

Environment Variable Expansion

Properties marked with [URI] attribute support automatic environment variable expansion using ${VAR} syntax:

public class Config : AConfiguration
{
    [URI]
    public string DatabasePath { get; init; }  // Expands ${DB_PATH}
    
    [URI]
    public List<string> SearchPaths { get; init; }  // Expands all items
    
    public string NormalPath { get; init; }  // No expansion
}

Syntax: ${VARIABLE_NAME} - Build fails with error if variable doesn't exist

API Reference

ConfigurationBuilder

// Factory
ConfigurationBuilder.CreateNew() : Result<ConfigurationBuilder>

// Constants
ConfigurationSectionKey : string = "configuration"  // Section key for configuration data

// Methods
WithJsonUriStrings(params string[] uris) : Result<ConfigurationBuilder>
WithEmbeddedJsonResources(params string[] resources) : Result<ConfigurationBuilder>
WithLocalSecrets(params string[] secrets) : Result<ConfigurationBuilder>
WithRawJsonStrings(params string[] json) : Result<ConfigurationBuilder>
WithAdditionalConfigurations(params IConfiguration[] configs) : Result<ConfigurationBuilder>
WithAdditionalConfigurationSourcesFrom(params IConfiguration[] configs) : Result<ConfigurationBuilder>
WithAdditionalConfigurationsFrom(params IConfiguration[] configs) : Result<ConfigurationBuilder>
WithAdditionalConfigurationSources(params ConfigurationSource[] sources) : Result<ConfigurationBuilder>
Build() : Result<IConfiguration>

ConfigurationBuilder<TConfiguration>

// Inherits all ConfigurationBuilder methods plus:
WithValidators(params IValidator<TConfiguration>[] validators) : Result<ConfigurationBuilder<TConfiguration>>
Build() : Result<TConfiguration>  // Returns typed config

ConfigurationSourceBuilder

// Factory
ConfigurationSourceBuilder.CreateNew() : Result<ConfigurationSourceBuilder>

// Constants
ConfigurationSourceSectionKey : string = "configurationSource"  // Section key for configuration sources

// Methods
WithRawJsonStrings(params string[] json) : Result<ConfigurationSourceBuilder>
WithJsonUriStrings(params string[] uris) : Result<ConfigurationSourceBuilder>
WithEmbeddedJsonResources(params string[] resources) : Result<ConfigurationSourceBuilder>
WithLocalSecrets(params string[] secrets) : Result<ConfigurationSourceBuilder>
WithAdditionalConfigurationSources(params ConfigurationSource[] sources) : Result<ConfigurationSourceBuilder>
Build() : Result<ConfigurationSource>

Error Handling

All operations return Result<T> from FluentResults:

var result = builder.Build();

if (result.IsFailed)
{
    foreach (var error in result.Errors)
    {
        Console.WriteLine(error.Message);
    }
}

Best Practices

  • Use typed configuration classes inheriting AConfiguration
  • Validate configuration with IValidator<T>
  • Handle Result failures explicitly
  • Use [URI] attribute for environment-specific values
  • Avoid storing sensitive data in code
  • Use WithAdditionalConfigurationSourcesFrom to load configuration sources from external configurations
  • Use WithAdditionalConfigurationsFrom to load configuration data from external configurations

Examples

Production Configuration

public class ProductionConfig : AConfiguration
{
    [URI]
    public string DatabaseConnection { get; init; }
    
    [URI]
    public string LogDirectory { get; init; }
    
    public int PoolSize { get; init; }
}

var builder = ConfigurationBuilder<ProductionConfig>.CreateNew();
builder.WithJsonUriStrings("file:///etc/app/config.json");
builder.WithLocalSecrets("ProductionSecrets");
builder.WithValidators(new ProductionValidator());
var result = builder.Build();

Testing Configuration

var builder = ConfigurationBuilder<AppConfig>.CreateNew();
builder.WithRawJsonStrings(@"{
    ""ConnectionString"": ""Server=localhost;Database=test"",
    ""MaxRetries"": 3
}");
var result = builder.Build();

if (result.IsSuccess)
{
    var testConfig = result.Value;
}

Loading Configuration from External Sources

// Load configuration sources from another configuration
var externalConfig = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
    .AddInMemoryCollection(new Dictionary<string, string> 
    {
        { "configurationSource:RawJsonStrings:0", "{\"Key\":\"Value\"}" }
    })
    .Build();

var builder = ConfigurationBuilder.CreateNew();
builder.WithAdditionalConfigurationSourcesFrom(externalConfig);
var result = builder.Build();

Composing Configuration Sources

// Create and reuse configuration sources
var baseSource = ConfigurationSourceBuilder.CreateNew()
    .Bind(b => b.WithRawJsonStrings("{\"BaseKey\":\"BaseValue\"}"))
    .Bind(b => b.Build())
    .Value;

var builder = ConfigurationBuilder.CreateNew();
builder.WithAdditionalConfigurationSources(baseSource);
builder.WithRawJsonStrings("{\"AdditionalKey\":\"AdditionalValue\"}");
var result = builder.Build();

if (result.IsSuccess)
{
    var config = result.Value;
    var baseValue = config["BaseKey"];           // "BaseValue"
    var additionalValue = config["AdditionalKey"]; // "AdditionalValue"
}

Loading Configuration Data from External Sources

// Load configuration data from another configuration
var externalConfig = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
    .AddInMemoryCollection(new Dictionary<string, string> 
    {
        { "configuration:Database", "Server=localhost" }
    })
    .Build();

var builder = ConfigurationBuilder.CreateNew();
builder.WithAdditionalConfigurationsFrom(externalConfig);
var result = builder.Build();

if (result.IsSuccess)
{
    var value = result.Value["Database"]; // "Server=localhost"
}

License

Licensed under the terms specified in LICENSE.

Contributing

Contributions welcome! This project uses:

  • Result pattern for error handling
  • Comprehensive XML documentation

Author: Prashant Nagoorkar
Repository: https://github.com/pnagoorkar/Baubit.Configuration

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Baubit.Configuration:

Package Downloads
Baubit.Caching

Thread-safe insertion-ordered cache with O(1) lookups, two-tier storage (bounded L1, unbounded L2), and async enumeration. Provides deletion-resilient iteration, automatic multi-consumer memory management, and zero-latency producer-consumer coordination using GuidV7 time-ordered identifiers. Ideal for event sourcing, audit logs, message queues, and time-series caching scenarios.

Baubit.DI

Modularity framework for .NET with configuration-driven module composition. Load modules from JSON, code, or both.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2025.49.1 1,222 12/1/2025
2025.48.3 488 11/29/2025
2025.48.1 415 11/25/2025
2025.47.5 210 11/23/2025
2025.47.4 173 11/22/2025
2025.47.1 273 11/21/2025