DotNetExtras.Configuration 1.0.1

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

DotNetExtras.Configuration

DotNetExtras.Configuration is a .NET Core library that simplifies loading, reading, and transforming configuration settings of .NET applications.

Use the DotNetExtras.Configuration library to:

  • Load configuration from JSON files, JSON strings, or Dictionary objects (useful for mocking application setting in unit tests).
  • Retrieve application settings and assign them to strongly-typed variables including primitive types (string, int, enum, boolean), arrays, collections, lists, hash sets, and dictionaries.
  • Set configuration once during application startup and access it from anywhere in the code.
  • Reload configuration settings.

Usage

The following examples illustrate how to use the DotNetExtras.Configuration API:

using Microsoft.Extensions.Configuration
using DotNetExtras.Configuration;
...
IConfiguration? config = null;

// Load configuration from a JSON file.
config = AppSettings.Load.FromJsonFile("C:\\AppSettings.json");

// Load configuration from a JSON string.
config = AppSettings.Load.FromJsonFile("{\"a\":{\"b\":\"c\"}}");

// Load configuration from a dictionary (keys of array elements must be indexed).
config = AppSettings.Load.FromDictionary(
    new Dictionary<string,string?>
    {
        {"A", "ValueA"},
        {"B:X", "ValueB"},
        {"C:Z:0", "ValueC"},
        {"C:Z:1", "ValueD"},
        {"C:Z:2", "ValueE"},
    }
);

// Save configuration in a static global variable.
AppSettings.Global.Set(config);

// Get configuration from the static global variable.
config = AppSettings.Global.Get();

// Reinitialize the configuration from the original provider.
AppSettings.Reload(config);

// Get a strongly-typed primitive value from the configuration.
string? a = AppSettings.GetValue<string>("KeyX:SubKeyA");
int? b = AppSettings.GetValue<int>("KeyX:SubKeyB");
bool? c = AppSettings.GetValue<bool>("KeyX:SubKeyC");

// Get a strongly typed collection value from the configuration.
string[]? d1 = AppSettings.GetArrayValue<string[]>("KeyX:SubKeyD1");
int[]? d2 = AppSettings.GetArrayValue<int[]>("KeyX:SubKeyD2"");
List<string>? e1 = AppSettings.GetListValue<List<string>>("KeyX:SubKeyE1");
List<int>? e2 = AppSettings.GetListValue<List<string>>("KeyX:SubKeyE2");
HashSet<string>? f1 = AppSettings.GetHashSetValue<string>("KeyX:SubKeyF1");
HashSet<int>? f2 = AppSettings.GetHashSetValue<string>("KeyX:SubKeyF2");
Dictionary<string, string>? g1 = AppSettings.GetDictionaryValue<string, string>("KeyX:SubKeyG1");
Dictionary<string, int>? g2 = AppSettings.GetDictionaryValue<string, int>("KeyX:SubKeyG2");

// Get a strongly typed enum value from the configuration.
MyEnum? h = AppSettings.GetEnumValue<MyEnum>("KeyX:SubKeyH");

Documentation

For complete documentation, usage details, and code samples, see:

Package

Install the latest version of the DotNetExtras.Configuration NuGet package from:

See also

Check out other DotNetExtras libraries at:

Product Compatible and additional computed target framework versions.
.NET 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 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. 
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.0.1 64 8/15/2025
1.0.0 123 8/11/2025

Fixed typo in the method name.