Skip to main content
.NETFramework4.6.2net8.0net9.0.NETStandard2.0

Implementation of key-value pair based configuration for Microsoft.Extensions.Configuration. Includes the memory configuration provider.

Published
Jul 9, 2024
2y ago
Total Downloads
7.1B
7,087,347,881

Install

dotnet add package Microsoft.Extensions.Configuration --version 9.0.0-preview.6.24327.7
ProductVersions
.NET
net8.0net9.0
.NET Standard
netstandard2.0
Other
.NETFramework4.6.2

README

About

Microsoft.Extensions.Configuration is combined with a core configuration abstraction under Microsoft.Extensions.Configuration.Abstractions that allows for building different kinds of configuration providers to retrieve key/value pair configuration values from in the form of IConfiguration. There are a number of built-in configuration provider implementations to read from environment variables, in-memory collections, JSON, INI or XML files. Aside from the built-in variations, there are more shipped libraries shipped by community for integration with various configuration service and other data sources.

Key Features

  • In-memory configuration provider
  • Chained configuration provider for chaining multiple confiugration providers together.
  • Base types that implement configuration abstraction interfaces that can be used when implementing other configuration providers.

How to Use

using Microsoft.Extensions.Configuration;

var configurationBuilder = new ConfigurationBuilder();

configurationBuilder.AddInMemoryCollection(
    new Dictionary<string, string?>
    {
        ["Setting1"] = "value",
        ["MyOptions:Enabled"] = bool.TrueString,
    });

configurationBuilder.AddInMemoryCollection(
    new Dictionary<string, string?>
    {
        ["Setting2"] = "value2",
        ["MyOptions:Enabled"] = bool.FalseString,
    });

var config = configurationBuilder.Build();

// note case-insensitive
Console.WriteLine(config["setting1"]);
Console.WriteLine(config["setting2"]);

// note last in wins
Console.WriteLine(config["MyOptions:Enabled"]);

Main Types

The main types provided by this library are:

  • Microsoft.Extensions.Configuration.ConfigurationBuilder
  • Microsoft.Extensions.Configuration.ConfigurationManager
  • Microsoft.Extensions.Configuration.ConfigurationRoot
  • Microsoft.Extensions.Configuration.ConfigurationSection

Additional Documentation

Related Packages

Feedback & Contributing

Microsoft.Extensions.Configuration is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Changes from Previous Version

No structural changes between v9.0.0-preview.5.24306.7 and v9.0.0-preview.6.24327.7.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.