Microsoft.Extensions.Options.ConfigurationExtensions 9.0.21

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 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.

Showing the top 20 packages that depend on Microsoft.Extensions.Options.ConfigurationExtensions.

Packages Downloads
Microsoft.Extensions.Logging.Configuration
Configuration support for Microsoft.Extensions.Logging.
1,754
Microsoft.Extensions.Diagnostics
This package includes the default implementation of IMeterFactory and additional extension methods to easily register it with the Dependency Injection framework.
1,735
Microsoft.Extensions.Logging.Configuration
Configuration support for Microsoft.Extensions.Logging.
1,734
Microsoft.Extensions.Diagnostics
This package includes the default implementation of IMeterFactory and additional extension methods to easily register it with the Dependency Injection framework.
118
Microsoft.Extensions.Logging.Configuration
Configuration support for Microsoft.Extensions.Logging.
101
Microsoft.Extensions.Diagnostics
This package includes the default implementation of IMeterFactory and additional extension methods to easily register it with the Dependency Injection framework.
93
Microsoft.Extensions.Diagnostics
This package includes the default implementation of IMeterFactory and additional extension methods to easily register it with the Dependency Injection framework.
81
Microsoft.Extensions.Logging.Configuration
Configuration support for Microsoft.Extensions.Logging.
70
Microsoft.Extensions.Logging.Configuration
Configuration support for Microsoft.Extensions.Logging.
65
Serilog.Settings.Configuration
Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.
59
Microsoft.Extensions.Resilience
Extensions to the Polly libraries to enrich telemetry with metadata and exception summaries.
58
Microsoft.Extensions.Logging.Configuration
Configuration support for Microsoft.Extensions.Logging.
57
Microsoft.Extensions.Resilience
Extensions to the Polly libraries to enrich telemetry with metadata and exception summaries.
57
Microsoft.Extensions.Diagnostics
This package includes the default implementation of IMeterFactory and additional extension methods to easily register it with the Dependency Injection framework.
56
SuperSocket.Command
SuperSocket command pattern library which allow you to handle requests with commands.
55
Microsoft.Extensions.Logging.Console
Console logger provider implementation for Microsoft.Extensions.Logging. When using NuGet 3.x this package requires at least version 3.4.
54
SuperSocket.Command
SuperSocket command pattern library which allow you to handle requests with commands.
53
IdentityServer4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
52

Version Downloads Last updated
11.0.0-rc.2.26504.105 7 10/13/2026
11.0.0-rc.1.26425.128 17 09/09/2026
11.0.0-preview.7.26381.103 22 08/12/2026
11.0.0-preview.6.26359.118 17 07/14/2026
11.0.0-preview.5.26302.115 29 06/12/2026
11.0.0-preview.4.26230.115 30 05/14/2026
11.0.0-preview.3.26207.106 45 04/15/2026
11.0.0-preview.2.26159.112 45 03/14/2026
11.0.0-preview.1.26104.118 41 02/12/2026
10.0.13 8 10/13/2026
10.0.12 16 09/09/2026
10.0.11 110 08/13/2026
10.0.10 24 07/14/2026
10.0.9 26 06/12/2026
10.0.8 30 05/14/2026
10.0.7 1,745 04/21/2026
10.0.6 41 04/16/2026
10.0.5 41 03/14/2026
10.0.4 36 03/11/2026
10.0.3 46 02/15/2026
10.0.2 58 01/15/2026
10.0.1 6 10/02/2026
10.0.0 106 12/14/2025
10.0.0-rc.2.25502.107 49 12/14/2025
10.0.0-rc.1.25451.107 40 12/12/2025
10.0.0-preview.7.25380.108 38 12/16/2025
10.0.0-preview.6.25358.103 6 09/28/2026
10.0.0-preview.5.25277.114 51 12/11/2025
10.0.0-preview.4.25258.110 33 12/14/2025
10.0.0-preview.3.25171.5 5 09/28/2026
10.0.0-preview.2.25163.2 29 01/04/2026
10.0.0-preview.1.25080.5 47 12/14/2025
9.0.21 9 10/13/2026
9.0.20 16 09/11/2026
9.0.19 19 08/13/2026
9.0.18 22 07/14/2026
9.0.17 26 06/13/2026
9.0.16 24 05/14/2026
9.0.15 40 04/16/2026
9.0.14 34 03/13/2026
9.0.13 49 02/11/2026
9.0.12 55 01/15/2026
9.0.11 52 12/18/2025
9.0.10 49 12/18/2025
9.0.9 7 09/28/2026
9.0.8 51 12/13/2025
9.0.7 43 12/12/2025
9.0.6 49 12/16/2025
9.0.5 55 12/11/2025
9.0.4 39 12/11/2025
9.0.3 55 12/14/2025
9.0.2 46 12/21/2025
9.0.1 49 12/12/2025
9.0.0 6 09/28/2026
9.0.0-rc.2.24473.5 39 01/06/2026
9.0.0-rc.1.24431.7 36 12/13/2025
9.0.0-preview.7.24405.7 43 12/14/2025
9.0.0-preview.6.24327.7 37 12/14/2025
9.0.0-preview.5.24306.7 29 12/14/2025
9.0.0-preview.4.24266.19 25 12/15/2025
9.0.0-preview.3.24172.9 43 12/14/2025
9.0.0-preview.2.24128.5 45 12/14/2025
9.0.0-preview.1.24080.9 39 12/14/2025
8.0.0 42 09/28/2026
8.0.0-rc.2.23479.6 39 12/14/2025
8.0.0-rc.1.23419.4 44 12/14/2025
8.0.0-preview.7.23375.6 3 10/04/2026
8.0.0-preview.6.23329.7 45 12/25/2025
8.0.0-preview.5.23280.8 27 12/14/2025
8.0.0-preview.4.23259.5 38 12/14/2025
8.0.0-preview.3.23174.8 42 12/13/2025
8.0.0-preview.2.23128.3 46 12/14/2025
8.0.0-preview.1.23110.8 34 12/14/2025
7.0.0 40 12/12/2025
7.0.0-rc.2.22472.3 3 09/28/2026
7.0.0-rc.1.22426.10 31 12/15/2025
7.0.0-preview.7.22375.6 42 12/14/2025
7.0.0-preview.6.22324.4 35 01/05/2026
7.0.0-preview.5.22301.12 42 12/16/2025
7.0.0-preview.4.22229.4 38 12/14/2025
7.0.0-preview.3.22175.4 38 12/14/2025
7.0.0-preview.2.22152.2 45 01/03/2026
7.0.0-preview.1.22076.8 44 12/16/2025
6.0.2-mauipre.1.22102.15 7 09/28/2026
6.0.2-mauipre.1.22054.8 40 12/15/2025
6.0.1 47 12/30/2025
6.0.0 64 12/11/2025
6.0.0-rc.2.21480.5 38 12/28/2025
6.0.0-rc.1.21451.13 39 01/06/2026
6.0.0-preview.7.21377.19 35 12/14/2025
6.0.0-preview.6.21352.12 41 01/06/2026
6.0.0-preview.5.21301.5 42 01/01/2026
6.0.0-preview.4.21253.7 39 12/21/2025
6.0.0-preview.3.21201.4 33 12/15/2025
6.0.0-preview.2.21154.6 43 12/12/2025
6.0.0-preview.1.21102.12 42 12/22/2025
5.0.0 31 12/14/2025
5.0.0-rc.2.20475.5 42 12/12/2025
5.0.0-rc.1.20451.14 39 01/06/2026
5.0.0-preview.8.20407.11 36 01/05/2026
5.0.0-preview.7.20364.11 30 12/12/2025
5.0.0-preview.6.20305.6 42 12/14/2025
5.0.0-preview.5.20278.1 44 01/05/2026
5.0.0-preview.4.20251.6 2 10/11/2026
5.0.0-preview.3.20215.2 38 01/07/2026
5.0.0-preview.2.20160.3 36 12/14/2025
5.0.0-preview.1.20120.4 24 01/06/2026
3.1.32 43 12/21/2025
3.1.31 31 12/21/2025
3.1.30 43 12/15/2025
3.1.29 42 12/13/2025
3.1.28 44 12/15/2025
3.1.27 34 12/14/2025
3.1.26 40 12/14/2025
3.1.25 42 12/21/2025
3.1.24 49 12/15/2025
3.1.23 34 12/14/2025
3.1.22 49 12/19/2025
3.1.21 39 12/21/2025
3.1.20 46 12/17/2025
3.1.19 37 12/14/2025
3.1.18 42 12/14/2025
3.1.17 53 12/18/2025
3.1.16 34 12/14/2025
3.1.15 33 12/11/2025
3.1.14 36 12/17/2025
3.1.13 44 12/14/2025
3.1.12 51 12/14/2025
3.1.11 43 12/21/2025
3.1.10 27 12/21/2025
3.1.9 34 12/15/2025
3.1.8 45 12/21/2025
3.1.7 51 12/17/2025
3.1.6 46 12/21/2025
3.1.5 51 12/13/2025
3.1.4 40 12/21/2025
3.1.3 39 12/14/2025
3.1.2 39 12/21/2025
3.1.1 44 12/21/2025
3.1.0 31 12/14/2025
3.1.0-preview3.19553.2 38 12/21/2025
3.1.0-preview2.19525.4 45 01/02/2026
3.1.0-preview1.19506.1 31 12/21/2025
3.0.3 45 12/14/2025
3.0.2 48 12/21/2025
3.0.1 48 12/15/2025
3.0.0 36 12/21/2025
3.0.0-rc1.19456.10 41 12/14/2025
3.0.0-preview9.19423.4 39 12/12/2025
3.0.0-preview8.19405.4 3 09/28/2026
3.0.0-preview7.19362.4 6 09/28/2026
3.0.0-preview6.19304.6 36 12/21/2025
3.0.0-preview5.19227.9 40 12/14/2025
3.0.0-preview4.19216.2 40 12/27/2025
3.0.0-preview3.19153.1 51 12/21/2025
3.0.0-preview.19074.2 51 01/03/2026
3.0.0-preview.18572.1 43 01/05/2026
2.2.0 48 12/16/2025
2.2.0-preview3-35497 50 12/15/2025
2.2.0-preview2-35157 8 09/28/2026
2.2.0-preview1-35029 45 12/21/2025
2.1.1 51 12/16/2025
2.1.0 41 12/16/2025
2.1.0-rc1-final 45 12/21/2025
2.1.0-preview2-final 37 12/21/2025
2.1.0-preview1-final 6 09/28/2026
2.0.2 32 12/21/2025
2.0.1 36 12/21/2025
2.0.0 66 12/15/2025
2.0.0-preview2-final 3 10/08/2026
2.0.0-preview1-final 40 12/21/2025
1.1.2 39 12/21/2025
1.1.1 45 12/14/2025
1.1.0 34 12/14/2025
1.1.0-preview1-final 41 12/21/2025
1.0.2 40 12/14/2025
1.0.1 37 12/21/2025
1.0.0 53 12/21/2025
1.0.0-rc2-final 36 12/21/2025