OutWit.Common.Configuration 1.1.0

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

OutWit.Common.Configuration

Overview

OutWit.Common.Configuration provides a fluent API for building and binding Microsoft.Extensions.Configuration settings in .NET applications. It simplifies loading JSON configuration files with environment-specific overrides and binding entire configuration trees to strongly-typed settings classes via a single call.

Built on top of Microsoft.Extensions.Configuration, the library adds two things the standard API does not provide out of the box:

  1. Assembly-relative file resolution � configuration files are resolved relative to the assembly directory, not Environment.CurrentDirectory. This is especially useful for plugin architectures and test runners.
  2. [ConfigSection] attribute � allows mapping individual properties of a settings class to arbitrary configuration section names, so the POCO shape does not have to mirror the JSON structure.
Install
Install-Package OutWit.Common.Configuration

or

dotnet add package OutWit.Common.Configuration

Target Frameworks

TFM Microsoft.Extensions.Configuration
net10.0, netstandard2.0 10.0.x
net9.0, net8.0 9.0.x
net7.0, net6.0 8.0.x

Features

1. Fluent Configuration Builder

Build an IConfiguration instance from JSON files with optional environment-specific overrides using a fluent API:

using OutWit.Common.Configuration;

// Minimal � loads appsettings.json from the assembly directory
var config = ConfigurationUtils
    .For(Assembly.GetExecutingAssembly())
    .Build();

The full builder chain:

var config = ConfigurationUtils
    .For(Assembly.GetExecutingAssembly())   // base path = assembly directory
    .WithFileName("mysettings")             // default is "appsettings"
    .WithEnvironment(ConfigurationEnvironment.Development)
    .Build();

This resolves two files from the directory where the calling assembly DLL is located:

  1. mysettings.json (optional, reloadOnChange: true)
  2. mysettings.Development.json (optional, reloadOnChange: true)

Values from the environment file override the base file, following the standard Microsoft.Extensions.Configuration layering convention.

The environment can also be specified as a plain string:

var config = ConfigurationUtils
    .For(Assembly.GetExecutingAssembly())
    .WithEnvironment("Staging")
    .Build();

2. Attribute-Based Section Binding

The BindSettings<T>() extension method creates a new T and populates each public read-write property from the corresponding IConfigurationSection. By default, the section name equals the property name. Use the [ConfigSection] attribute to override it:

public class AppSettings
{
    // Binds from section "AppName" (matches property name)
    public string AppName { get; set; }

    // Binds from section "ConnectionStrings" instead of "Database"
    [ConfigSection("ConnectionStrings")]
    public ConnectionDetails Database { get; set; }

    // Binds from section "Logging:LogLevel" (nested path)
    [ConfigSection("Logging:LogLevel")]
    public string LogLevel { get; set; }
}

public class ConnectionDetails
{
    public string DefaultConnection { get; set; }
}

Usage:

var settings = config.BindSettings<AppSettings>();

Console.WriteLine(settings.AppName);                    // from "AppName" section
Console.WriteLine(settings.Database.DefaultConnection); // from "ConnectionStrings" section
Console.WriteLine(settings.LogLevel);                   // from "Logging:LogLevel" section

How it works under the hood:

  1. Creates a new instance of T via the parameterless constructor.
  2. Enumerates all public instance properties with both a getter and a setter.
  3. For each property, reads the [ConfigSection("...")] attribute; falls back to the property name.
  4. Calls IConfiguration.GetSection(name).Get(propertyType) to bind the section.
  5. Properties whose sections do not exist in the configuration are left at their default values.

3. Supported Environments

The ConfigurationEnvironment enum provides the standard set of well-known environment names:

Value Typical usage
Development Local dev machines, hot reload, verbose logging
Production Live deployments, minimal logging
Test Automated test runners, in-memory or mock services

These can be passed directly to WithEnvironment():

.WithEnvironment(ConfigurationEnvironment.Production)

API Reference

Class / Method Description
ConfigurationUtils.For(Assembly) Creates a ConfigurationInfo builder anchored to the assembly's directory
.WithFileName(string) Sets the base config file name (default: "appsettings")
.WithEnvironment(string) Sets the environment name for overlay files
.WithEnvironment(ConfigurationEnvironment) Same, using the enum
.Build() Builds and returns IConfiguration
IConfiguration.BindSettings<T>() Binds configuration sections to a new T instance using reflection and [ConfigSection]
ConfigSectionAttribute Attribute that overrides the configuration section name for a property

License

Licensed under the Apache License, Version 2.0. See LICENSE.

Attribution (optional)

If you use OutWit.Common.Configuration in a product, a mention is appreciated (but not required), for example: "Powered by OutWit.Common.Configuration (https://ratner.io/)".

Trademark / Project name

"OutWit" and the OutWit logo are used to identify the official project by Dmitry Ratner.

You may:

  • refer to the project name in a factual way (e.g., "built with OutWit.Common.Configuration");
  • use the name to indicate compatibility (e.g., "OutWit.Common.Configuration-compatible").

You may not:

  • use "OutWit.Common.Configuration" as the name of a fork or a derived product in a way that implies it is the official project;
  • use the OutWit.Common.Configuration logo to promote forks or derived products without permission.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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 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 is compatible.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 158 5/24/2026
1.0.0 181 2/7/2026