OutWit.Common.Configuration
1.0.0
See the version list below for details.
dotnet add package OutWit.Common.Configuration --version 1.0.0
NuGet\Install-Package OutWit.Common.Configuration -Version 1.0.0
<PackageReference Include="OutWit.Common.Configuration" Version="1.0.0" />
<PackageVersion Include="OutWit.Common.Configuration" Version="1.0.0" />
<PackageReference Include="OutWit.Common.Configuration" />
paket add OutWit.Common.Configuration --version 1.0.0
#r "nuget: OutWit.Common.Configuration, 1.0.0"
#:package OutWit.Common.Configuration@1.0.0
#addin nuget:?package=OutWit.Common.Configuration&version=1.0.0
#tool nuget:?package=OutWit.Common.Configuration&version=1.0.0
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:
- 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. [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:
mysettings.json(optional,reloadOnChange: true)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:
- Creates a new instance of
Tvia the parameterless constructor. - Enumerates all public instance properties with both a getter and a setter.
- For each property, reads the
[ConfigSection("...")]attribute; falls back to the property name. - Calls
IConfiguration.GetSection(name).Get(propertyType)to bind the section. - 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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 10.0.2)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.2)
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.2)
- Microsoft.Extensions.Configuration.Json (>= 10.0.2)
-
net10.0
- Microsoft.Extensions.Configuration (>= 10.0.2)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.2)
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.2)
- Microsoft.Extensions.Configuration.Json (>= 10.0.2)
-
net6.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Configuration.FileExtensions (>= 8.0.1)
- Microsoft.Extensions.Configuration.Json (>= 8.0.1)
-
net7.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Configuration.FileExtensions (>= 8.0.1)
- Microsoft.Extensions.Configuration.Json (>= 8.0.1)
-
net8.0
- Microsoft.Extensions.Configuration (>= 9.0.12)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.12)
- Microsoft.Extensions.Configuration.FileExtensions (>= 9.0.12)
- Microsoft.Extensions.Configuration.Json (>= 9.0.12)
-
net9.0
- Microsoft.Extensions.Configuration (>= 9.0.12)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.12)
- Microsoft.Extensions.Configuration.FileExtensions (>= 9.0.12)
- Microsoft.Extensions.Configuration.Json (>= 9.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.