Microsoft.Extensions.Options.ConfigurationExtensions 8.0.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Microsoft.Extensions.Options.ConfigurationExtensions --version 8.0.0
NuGet\Install-Package Microsoft.Extensions.Options.ConfigurationExtensions -Version 8.0.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="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Microsoft.Extensions.Options.ConfigurationExtensions --version 8.0.0
#r "nuget: Microsoft.Extensions.Options.ConfigurationExtensions, 8.0.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.
// Install Microsoft.Extensions.Options.ConfigurationExtensions as a Cake Addin
#addin nuget:?package=Microsoft.Extensions.Options.ConfigurationExtensions&version=8.0.0

// Install Microsoft.Extensions.Options.ConfigurationExtensions as a Cake Tool
#tool nuget:?package=Microsoft.Extensions.Options.ConfigurationExtensions&version=8.0.0

About

Microsoft.Extensions.Options.ConfigurationExtensions provides additional configuration-specific functionality related to Options.

Key Features

  • Extension methods for OptionsBuilder for configuration binding
  • Extension methods for IServiceCollection for Options configuration
  • ConfigurationChangeTokenSource<TOptions> for monitoring configuration changes

How to Use

Options Configuration binding
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

class Program
{
    // appsettings.json contents:
    // {
    //   "MyOptions": {
    //     "Setting1": "Value1",
    //     "Setting2": "Value2"
    //   }
    // }

    static void Main(string[] args)
    {
        IConfiguration configuration = new ConfigurationBuilder()
            .SetBasePath(Environment.CurrentDirectory)
            .AddJsonFile("appsettings.json")
            .Build();

        IServiceCollection services = new ServiceCollection();

        // Bind the configuration to MyOptions
        services.Configure<MyOptions>(configuration.GetSection("MyOptions"));

        IServiceProvider serviceProvider = services.BuildServiceProvider();

        // Retrieve MyOptions using dependency injection
        var myOptions = serviceProvider.GetRequiredService<IOptions<MyOptions>>().Value;

        // Access the bound configuration values
        Console.WriteLine($"Setting1: {myOptions.Setting1}");
        Console.WriteLine($"Setting2: {myOptions.Setting2}");
    }
}

public class MyOptions
{
    public string Setting1 { get; set; }
    public string Setting2 { get; set; }
}

Monitoring options configuration changes
// Assume we have a class that represents some options
public class MyOptions
{
    public string Name { get; set; }
    public int Age { get; set; }
}

// appsettings.json contents:
// {
//   "MyOptions": {
//     "Name": "Alice",
//     "Age": 25
//   }
// }

// Assume we have a configuration object that contains some settings
var config = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();

// We can use the ConfigurationChangeTokenSource to create a change token source for the options
var changeTokenSource = new ConfigurationChangeTokenSource<MyOptions>(config.GetSection("MyOptions"));

// We can register the change token source with the options monitor
services.AddOptions<MyOptions>()
    .Configure(options =>
    {
        // Configure the options with the configuration values
        config.GetSection("MyOptions").Bind(options);
    })
    .AddChangeTokenSource(changeTokenSource);

// Now we can inject the options monitor into any class that needs them
public class MyClass
{
    private readonly IOptionsMonitor<MyOptions> _optionsMonitor;

    public MyClass(IOptionsMonitor<MyOptions> optionsMonitor)
    {
        _optionsMonitor = optionsMonitor;
    }

    public void DoSomething()
    {
        // Can access the current options value like this
        var options = _optionsMonitor.CurrentValue;
        var name = options.Name;
        var age = options.Age;
        // Do something with name and age

        // Can also register a callback to be notified when the options change
        _optionsMonitor.OnChange(newOptions =>
        {
            // Do something when the options change
        });
    }
}

Main Types

The main types provided by this library are:

  • ConfigurationChangeTokenSource
  • OptionsBuilderConfigurationExtensions
  • OptionsConfigurationServiceCollectionExtensions

Additional Documentation

Feedback & Contributing

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

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. 
.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 is compatible.  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 (3.1K)

Showing the top 5 NuGet packages that depend on Microsoft.Extensions.Options.ConfigurationExtensions:

Package Downloads
Microsoft.Extensions.Logging.Configuration The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Configuration support for Microsoft.Extensions.Logging.

Microsoft.AspNetCore.App The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Provides a default set of APIs for building an ASP.NET Core application. This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.

Microsoft.AspNetCore.All The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Provides a default set of APIs for building an ASP.NET Core application, and also includes API for third-party integrations with ASP.NET Core. This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.

Volo.Abp.Core The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Package Description

App.Metrics.AspNetCore.Core

App Metrics ASP.NET Core core components.

GitHub repositories (239)

Showing the top 5 popular GitHub repositories that depend on Microsoft.Extensions.Options.ConfigurationExtensions:

Repository Stars
App-vNext/Polly
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
abpframework/abp
Open Source Web Application Framework for ASP.NET Core. Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET and the ASP.NET Core platforms. Provides the fundamental infrastructure, production-ready startup templates, application modules, UI themes, tooling, guides and documentation.
dotnet/orleans
Cloud Native application framework for .NET
JeffreySu/WeiXinMPSDK
微信全平台 SDK Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 6.0、.NET 8.0。已支持微信公众号、小程序、小游戏、微信支付、企业微信/企业号、开放平台、JSSDK、微信周边等全平台。 WeChat SDK for C#.
Version Downloads Last updated
9.0.0-preview.2.24128.5 2,513 3/12/2024
9.0.0-preview.1.24080.9 32,019 2/13/2024
8.0.0 18,704,553 11/14/2023
8.0.0-rc.2.23479.6 480,040 10/10/2023
8.0.0-rc.1.23419.4 234,344 9/12/2023
8.0.0-preview.7.23375.6 146,664 8/8/2023
8.0.0-preview.6.23329.7 74,857 7/11/2023
8.0.0-preview.5.23280.8 50,975 6/13/2023
8.0.0-preview.4.23259.5 125,081 5/16/2023
8.0.0-preview.3.23174.8 60,934 4/11/2023
8.0.0-preview.2.23128.3 42,635 3/14/2023
8.0.0-preview.1.23110.8 89,429 2/21/2023
7.0.0 78,325,731 11/7/2022
7.0.0-rc.2.22472.3 156,663 10/11/2022
7.0.0-rc.1.22426.10 72,775 9/14/2022
7.0.0-preview.7.22375.6 58,740 8/9/2022
7.0.0-preview.6.22324.4 50,439 7/12/2022
7.0.0-preview.5.22301.12 43,500 6/14/2022
7.0.0-preview.4.22229.4 49,340 5/10/2022
7.0.0-preview.3.22175.4 42,435 4/13/2022
7.0.0-preview.2.22152.2 15,076 3/14/2022
7.0.0-preview.1.22076.8 29,356 2/17/2022
6.0.2-mauipre.1.22102.15 38,085 2/15/2022
6.0.2-mauipre.1.22054.8 150,228 1/19/2022
6.0.0 207,252,151 11/8/2021
6.0.0-rc.2.21480.5 379,073 10/12/2021
6.0.0-rc.1.21451.13 269,870 9/14/2021
6.0.0-preview.7.21377.19 143,499 8/10/2021
6.0.0-preview.6.21352.12 82,393 7/14/2021
6.0.0-preview.5.21301.5 38,472 6/15/2021
6.0.0-preview.4.21253.7 31,098 5/24/2021
6.0.0-preview.3.21201.4 53,396 4/8/2021
6.0.0-preview.2.21154.6 80,837 3/11/2021
6.0.0-preview.1.21102.12 62,317 2/12/2021
5.0.0 142,918,659 11/9/2020
5.0.0-rc.2.20475.5 117,078 10/13/2020
5.0.0-rc.1.20451.14 266,706 9/14/2020
5.0.0-preview.8.20407.11 264,893 8/25/2020
5.0.0-preview.7.20364.11 43,324 7/21/2020
5.0.0-preview.6.20305.6 41,912 6/25/2020
5.0.0-preview.5.20278.1 20,652 6/10/2020
5.0.0-preview.4.20251.6 34,100 5/18/2020
5.0.0-preview.3.20215.2 28,535 4/23/2020
5.0.0-preview.2.20160.3 53,567 4/2/2020
5.0.0-preview.1.20120.4 30,746 3/16/2020
3.1.32 2,451,461 12/13/2022
3.1.31 833,412 11/8/2022
3.1.30 973,371 10/11/2022
3.1.29 471,407 9/13/2022
3.1.28 850,793 8/9/2022
3.1.27 877,435 7/12/2022
3.1.26 530,568 6/14/2022
3.1.25 1,050,493 5/10/2022
3.1.24 614,451 4/11/2022
3.1.23 1,418,716 3/8/2022
3.1.22 7,580,026 12/14/2021
3.1.21 2,989,124 11/7/2021
3.1.20 1,276,218 10/11/2021
3.1.19 1,418,042 9/14/2021
3.1.18 2,940,310 8/10/2021
3.1.17 2,363,963 7/13/2021
3.1.16 2,472,275 6/8/2021
3.1.15 3,748,987 5/11/2021
3.1.14 8,743,458 4/6/2021
3.1.13 5,986,665 3/9/2021
3.1.12 4,051,366 2/9/2021
3.1.11 4,732,092 1/12/2021
3.1.10 10,309,799 11/9/2020
3.1.9 11,645,903 10/13/2020
3.1.8 16,396,751 9/8/2020
3.1.7 9,611,581 8/11/2020
3.1.6 17,359,268 7/14/2020
3.1.5 17,105,626 6/9/2020
3.1.4 11,155,985 5/12/2020
3.1.3 17,931,917 3/24/2020
3.1.2 16,774,013 2/18/2020
3.1.1 13,591,001 1/14/2020
3.1.0 78,257,318 12/3/2019
3.1.0-preview3.19553.2 53,449 11/13/2019
3.1.0-preview2.19525.4 15,503 11/1/2019
3.1.0-preview1.19506.1 18,262 10/15/2019
3.0.3 544,557 2/18/2020
3.0.2 778,777 1/14/2020
3.0.1 2,058,314 11/18/2019
3.0.0 30,523,033 9/23/2019
3.0.0-rc1.19456.10 34,723 9/16/2019
3.0.0-preview9.19423.4 128,101 9/4/2019
3.0.0-preview8.19405.4 137,947 8/13/2019
3.0.0-preview7.19362.4 75,237 7/23/2019
3.0.0-preview6.19304.6 136,047 6/12/2019
3.0.0-preview5.19227.9 148,204 5/6/2019
3.0.0-preview4.19216.2 22,812 4/18/2019
3.0.0-preview3.19153.1 142,328 3/6/2019
3.0.0-preview.19074.2 93,159 1/29/2019
3.0.0-preview.18572.1 10,622 12/4/2018
2.2.0 75,807,529 12/3/2018
2.2.0-preview3-35497 137,799 10/17/2018
2.2.0-preview2-35157 62,438 9/12/2018
2.2.0-preview1-35029 32,418 8/22/2018
2.1.1 55,149,402 6/18/2018
2.1.0 148,438,074 5/29/2018
2.1.0-rc1-final 72,934 5/6/2018
2.1.0-preview2-final 63,009 4/10/2018
2.1.0-preview1-final 154,627 2/26/2018
2.0.2 5,818,363 5/7/2018
2.0.1 10,048,850 3/13/2018
2.0.0 302,634,859 8/11/2017
2.0.0-preview2-final 117,127 6/28/2017
2.0.0-preview1-final 38,300 5/10/2017
1.1.2 7,530,363 5/9/2017
1.1.1 2,664,394 3/6/2017
1.1.0 2,232,395 11/16/2016
1.1.0-preview1-final 15,444 10/24/2016
1.0.2 688,937 3/6/2017
1.0.1 244,436 12/12/2016
1.0.0 1,967,350 6/27/2016
1.0.0-rc2-final 23,004 5/16/2016