Microsoft.Extensions.Options.ConfigurationExtensions 9.0.4

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

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 was computed.  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 was computed.  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. 
.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 (4.0K)

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

Package Downloads
Microsoft.Extensions.Logging.Configuration

Configuration support for Microsoft.Extensions.Logging.

Microsoft.Extensions.Diagnostics

This package includes the default implementation of IMeterFactory and additional extension methods to easily register it with the Dependency Injection framework.

Microsoft.Identity.Web.TokenAcquisition

Implementation for higher level API for confidential client applications (ASP.NET Core and SDK/.NET).

Microsoft.AspNetCore.App

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

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.

GitHub repositories (278)

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

Repository Stars
ardalis/CleanArchitecture
Clean Architecture Solution Template: A proven Clean Architecture Template for ASP.NET Core 9
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+.
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. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
chocolatey/choco
Chocolatey - the package manager for Windows
dotnet/orleans
Cloud Native application framework for .NET
JeffreySu/WeiXinMPSDK
微信全平台 .NET SDK, Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 8.0。已支持微信公众号、小程序、小游戏、微信支付、企业微信/企业号、开放平台、JSSDK、微信周边等全平台。 WeChat SDK for C#.
ThreeMammals/Ocelot
.NET API Gateway
dotnet/eShop
A reference .NET application implementing an eCommerce site
RayWangQvQ/BiliBiliToolPro
B 站(bilibili)自动任务工具,支持docker、青龙、k8s等多种部署方式。敏感肌也能用。
elsa-workflows/elsa-core
A .NET workflows library
ant-design-blazor/ant-design-blazor
🌈A rich set of enterprise-class UI components based on Ant Design and Blazor.
LykosAI/StabilityMatrix
Multi-Platform Package Manager for Stable Diffusion
anjoy8/Blog.Core
💖 ASP.NET Core 8.0 全家桶教程,前后端分离后端接口,vue教程姊妹篇,官方文档:
umbraco/Umbraco-CMS
Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
opserver/Opserver
Stack Exchange's Monitoring System
kerryjiang/SuperSocket
SuperSocket is a light weight, cross platform and extensible socket server application framework.
TelegramBots/Telegram.Bot
.NET Client for Telegram Bot API
fluentmigrator/fluentmigrator
Fluent migrations framework for .NET
dotnetcore/BootstrapBlazor
Bootstrap Blazor is an enterprise-level UI component library based on Bootstrap and Blazor.
Version Downloads Last updated
10.0.0-preview.3.25171.5 1,350 4/10/2025
10.0.0-preview.2.25163.2 13,300 3/18/2025
10.0.0-preview.1.25080.5 16,742 2/25/2025
9.0.4 223,441 4/8/2025
9.0.3 3,107,345 3/11/2025
9.0.2 5,253,641 2/11/2025
9.0.1 6,001,107 1/14/2025
9.0.0 22,425,609 11/12/2024
9.0.0-rc.2.24473.5 426,774 10/8/2024
9.0.0-rc.1.24431.7 280,540 9/10/2024
9.0.0-preview.7.24405.7 86,989 8/13/2024
9.0.0-preview.6.24327.7 137,942 7/9/2024
9.0.0-preview.5.24306.7 99,072 6/11/2024
9.0.0-preview.4.24266.19 68,528 5/21/2024
9.0.0-preview.3.24172.9 161,764 4/11/2024
9.0.0-preview.2.24128.5 82,832 3/12/2024
9.0.0-preview.1.24080.9 89,089 2/13/2024
8.0.0 226,610,506 11/14/2023
8.0.0-rc.2.23479.6 1,339,335 10/10/2023
8.0.0-rc.1.23419.4 468,064 9/12/2023
8.0.0-preview.7.23375.6 477,952 8/8/2023
8.0.0-preview.6.23329.7 103,416 7/11/2023
8.0.0-preview.5.23280.8 72,666 6/13/2023
8.0.0-preview.4.23259.5 288,123 5/16/2023
8.0.0-preview.3.23174.8 123,281 4/11/2023
8.0.0-preview.2.23128.3 55,710 3/14/2023
8.0.0-preview.1.23110.8 106,007 2/21/2023
7.0.0 119,839,041 11/7/2022
7.0.0-rc.2.22472.3 179,619 10/11/2022
7.0.0-rc.1.22426.10 85,760 9/14/2022
7.0.0-preview.7.22375.6 67,146 8/9/2022
7.0.0-preview.6.22324.4 63,734 7/12/2022
7.0.0-preview.5.22301.12 49,615 6/14/2022
7.0.0-preview.4.22229.4 61,274 5/10/2022
7.0.0-preview.3.22175.4 56,935 4/13/2022
7.0.0-preview.2.22152.2 16,851 3/14/2022
7.0.0-preview.1.22076.8 32,169 2/17/2022
6.0.1 369,652 11/12/2024
6.0.0 299,047,517 11/8/2021
6.0.0-rc.2.21480.5 406,377 10/12/2021
6.0.0-rc.1.21451.13 288,452 9/14/2021
6.0.0-preview.7.21377.19 152,607 8/10/2021
6.0.0-preview.6.21352.12 90,448 7/14/2021
6.0.0-preview.5.21301.5 40,890 6/15/2021
6.0.0-preview.4.21253.7 34,098 5/24/2021
6.0.0-preview.3.21201.4 59,035 4/8/2021
6.0.0-preview.2.21154.6 85,042 3/11/2021 6.0.0-preview.2.21154.6 is deprecated because it is no longer maintained.
6.0.0-preview.1.21102.12 70,882 2/12/2021 6.0.0-preview.1.21102.12 is deprecated because it is no longer maintained.
5.0.0 184,070,345 11/9/2020 5.0.0 is deprecated because it is no longer maintained.
5.0.0-rc.2.20475.5 136,566 10/13/2020 5.0.0-rc.2.20475.5 is deprecated because it is no longer maintained.
5.0.0-rc.1.20451.14 269,228 9/14/2020 5.0.0-rc.1.20451.14 is deprecated because it is no longer maintained.
5.0.0-preview.8.20407.11 338,617 8/25/2020 5.0.0-preview.8.20407.11 is deprecated because it is no longer maintained.
5.0.0-preview.7.20364.11 45,660 7/21/2020 5.0.0-preview.7.20364.11 is deprecated because it is no longer maintained.
5.0.0-preview.6.20305.6 44,304 6/25/2020 5.0.0-preview.6.20305.6 is deprecated because it is no longer maintained.
5.0.0-preview.5.20278.1 23,316 6/10/2020 5.0.0-preview.5.20278.1 is deprecated because it is no longer maintained.
5.0.0-preview.4.20251.6 36,334 5/18/2020 5.0.0-preview.4.20251.6 is deprecated because it is no longer maintained.
5.0.0-preview.3.20215.2 32,254 4/23/2020 5.0.0-preview.3.20215.2 is deprecated because it is no longer maintained.
5.0.0-preview.2.20160.3 54,734 4/2/2020 5.0.0-preview.2.20160.3 is deprecated because it is no longer maintained.
5.0.0-preview.1.20120.4 32,833 3/16/2020 5.0.0-preview.1.20120.4 is deprecated because it is no longer maintained.
3.1.32 6,409,159 12/13/2022
3.1.31 1,129,488 11/8/2022
3.1.30 1,585,353 10/11/2022
3.1.29 658,940 9/13/2022
3.1.28 1,138,294 8/9/2022
3.1.27 1,149,346 7/12/2022
3.1.26 632,151 6/14/2022
3.1.25 1,248,489 5/10/2022
3.1.24 713,084 4/11/2022
3.1.23 1,804,683 3/8/2022
3.1.22 12,177,676 12/14/2021
3.1.21 3,580,103 11/7/2021
3.1.20 1,470,219 10/11/2021
3.1.19 1,613,877 9/14/2021
3.1.18 3,670,333 8/10/2021
3.1.17 2,677,572 7/13/2021
3.1.16 2,720,232 6/8/2021
3.1.15 4,280,480 5/11/2021
3.1.14 9,847,950 4/6/2021
3.1.13 6,559,135 3/9/2021
3.1.12 4,452,231 2/9/2021
3.1.11 5,617,209 1/12/2021
3.1.10 11,502,774 11/9/2020
3.1.9 12,979,842 10/13/2020
3.1.8 17,798,852 9/8/2020
3.1.7 10,595,212 8/11/2020
3.1.6 19,200,312 7/14/2020
3.1.5 18,644,012 6/9/2020
3.1.4 12,405,113 5/12/2020
3.1.3 19,809,938 3/24/2020
3.1.2 18,365,776 2/18/2020
3.1.1 15,301,668 1/14/2020
3.1.0 111,921,483 12/3/2019
3.1.0-preview3.19553.2 57,230 11/13/2019 3.1.0-preview3.19553.2 is deprecated because it is no longer maintained.
3.1.0-preview2.19525.4 15,936 11/1/2019 3.1.0-preview2.19525.4 is deprecated because it is no longer maintained.
3.1.0-preview1.19506.1 19,333 10/15/2019 3.1.0-preview1.19506.1 is deprecated because it is no longer maintained.
3.0.3 616,647 2/18/2020 3.0.3 is deprecated because it is no longer maintained.
3.0.2 788,488 1/14/2020 3.0.2 is deprecated because it is no longer maintained.
3.0.1 2,238,534 11/18/2019 3.0.1 is deprecated because it is no longer maintained.
3.0.0 34,795,374 9/23/2019 3.0.0 is deprecated because it is no longer maintained.
3.0.0-rc1.19456.10 35,308 9/16/2019 3.0.0-rc1.19456.10 is deprecated because it is no longer maintained.
3.0.0-preview9.19423.4 134,597 9/4/2019 3.0.0-preview9.19423.4 is deprecated because it is no longer maintained.
3.0.0-preview8.19405.4 157,592 8/13/2019 3.0.0-preview8.19405.4 is deprecated because it is no longer maintained.
3.0.0-preview7.19362.4 78,663 7/23/2019 3.0.0-preview7.19362.4 is deprecated because it is no longer maintained.
3.0.0-preview6.19304.6 146,954 6/12/2019 3.0.0-preview6.19304.6 is deprecated because it is no longer maintained.
3.0.0-preview5.19227.9 160,375 5/6/2019 3.0.0-preview5.19227.9 is deprecated because it is no longer maintained.
3.0.0-preview4.19216.2 23,888 4/18/2019 3.0.0-preview4.19216.2 is deprecated because it is no longer maintained.
3.0.0-preview3.19153.1 152,671 3/6/2019 3.0.0-preview3.19153.1 is deprecated because it is no longer maintained.
3.0.0-preview.19074.2 96,264 1/29/2019 3.0.0-preview.19074.2 is deprecated because it is no longer maintained.
3.0.0-preview.18572.1 11,129 12/4/2018 3.0.0-preview.18572.1 is deprecated because it is no longer maintained.
2.2.0 90,695,976 12/3/2018 2.2.0 is deprecated because it is no longer maintained.
2.2.0-preview3-35497 141,515 10/17/2018 2.2.0-preview3-35497 is deprecated because it is no longer maintained.
2.2.0-preview2-35157 65,326 9/12/2018 2.2.0-preview2-35157 is deprecated because it is no longer maintained.
2.2.0-preview1-35029 34,862 8/22/2018 2.2.0-preview1-35029 is deprecated because it is no longer maintained.
2.1.1 69,982,934 6/18/2018
2.1.0 202,099,813 5/29/2018
2.1.0-rc1-final 76,379 5/6/2018 2.1.0-rc1-final is deprecated because it is no longer maintained.
2.1.0-preview2-final 67,848 4/10/2018 2.1.0-preview2-final is deprecated because it is no longer maintained.
2.1.0-preview1-final 161,052 2/26/2018 2.1.0-preview1-final is deprecated because it is no longer maintained.
2.0.2 6,271,753 5/7/2018 2.0.2 is deprecated because it is no longer maintained.
2.0.1 10,491,589 3/13/2018 2.0.1 is deprecated because it is no longer maintained.
2.0.0 363,061,035 8/11/2017 2.0.0 is deprecated because it is no longer maintained.
2.0.0-preview2-final 125,107 6/28/2017 2.0.0-preview2-final is deprecated because it is no longer maintained.
2.0.0-preview1-final 40,154 5/10/2017 2.0.0-preview1-final is deprecated because it is no longer maintained.
1.1.2 8,376,149 5/9/2017 1.1.2 is deprecated because it is no longer maintained.
1.1.1 2,813,864 3/6/2017 1.1.1 is deprecated because it is no longer maintained.
1.1.0 2,440,698 11/16/2016 1.1.0 is deprecated because it is no longer maintained.
1.1.0-preview1-final 15,792 10/24/2016 1.1.0-preview1-final is deprecated because it is no longer maintained.
1.0.2 720,489 3/6/2017 1.0.2 is deprecated because it is no longer maintained.
1.0.1 260,922 12/12/2016 1.0.1 is deprecated because it is no longer maintained.
1.0.0 2,119,753 6/27/2016 1.0.0 is deprecated because it is no longer maintained.
1.0.0-rc2-final 23,821 5/16/2016 1.0.0-rc2-final is deprecated because it is no longer maintained.