Configuring contextual options with Microsoft.Extensions.Options.Contextual The article introduces the `Microsoft.Extensions.Options.Contextual` NuGet package, which provides APIs for dynamically configuring options objects based on a provided context (such as user location or country). It explains how to install the package and use the `IContextualOptions` interface to retrieve configured options at runtime, contrasting this approach with traditional global or named options configuration. The author explores the package's purpose and setup, ultimately leaving it to readers to decide if the library is worth adopting. In this post I take a brief look at the Microsoft.Extensions.Options.Contextual package that I came across the other day. I try to understand the purpose of the package, look at how to install and configure it, and finally consider whether it's something people should consider using themselves. What is Microsoft.Extensions.Options.Contextual? what-is-microsoft-extensions-options-contextual- I was browsing around in the dotnet repositories https://github.com/dotnet for something the other day, when I spotted this library: Microsoft.Extensions.Options.Contextual https://github.com/dotnet/extensions/tree/main/src/Libraries/Microsoft.Extensions.Options.Contextual . I was somewhat intrigued considering I hadn't heard this library mentioned before, or had seen it used. What's more, a little probing seemed to suggest it's not used by any other first party .NET libraries either. So what is it for, and how does it work? According to the library itself https://github.com/dotnet/extensions/tree/4e8e9a258918dacf17a5dd033f9a01a23fd6692d/src/Libraries/Microsoft.Extensions.Options.Contextual , the library provides: APIs for dynamically configuring options based on a given context That's pretty vague 😅 What are "options" and what is "context" here? It's likely easiest to understand with an example, even if it's a simple one. The example below is based on the documentation in the package https://github.com/dotnet/extensions/tree/main/src/Libraries/Microsoft.Extensions.Options.Contextual , using the classic "weather forecast" scenario. Configuring options based on another type configuring-options-based-on-another-type First of all, let's imagine we have some configuration options: internal class WeatherForecastOptions { public string TemperatureScale { get; set; } = "Celsius"; // Celsius or Fahrenheit public int ForecastDays { get; set; } } This is pretty standard stuff—which unit to use for temperature display, and how many days to include in the forecast. The interesting thing is how these options are configured. If you're doing global configuration for your app then you might have something like this using Configure and/or AddOptions : js var builder = WebApplication.CreateBuilder args ; builder.Services .AddOptions