Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

OptionsMonitorExample - IOptionsMonitor in ASP.NET Core

YouTube Blog Newsletter All Links LinkedIn

This project demonstrates how to use IOptionsMonitor<T> in ASP.NET Core to access strongly-typed configuration that can be observed for changes at runtime. It shows the .NET Options pattern for binding JSON configuration sections to C# classes and injecting them into minimal API endpoints.

The application creates a minimal ASP.NET Core Web API with a single GET /hello endpoint that reads from a SettingsOptions class bound to the Settings section in appsettings.json. The IOptionsMonitor<SettingsOptions> is injected directly into the route handler, and its CurrentValue property provides real-time access to configuration values including StringProperty and IntegerProperty. Unlike IOptions<T>, IOptionsMonitor<T> supports live reloading of configuration changes without restarting the application, making it ideal for long-lived services and background tasks.

This is a focused educational example of Microsoft's recommended configuration management approach in modern .NET 8 applications.

Getting Started

Prerequisites

  • .NET 8.0 SDK or later
  • An IDE such as Visual Studio, Visual Studio Code, or JetBrains Rider

Running the Project

dotnet run --project OptionsMonitorExample

Then navigate to https://localhost:<port>/hello or use the included .http file to test the endpoint.

Newsletter

If you found this useful and you want to learn more about C#, .NET, and software engineering, subscribe to the free Dev Leader Weekly newsletter:

Subscribe to Dev Leader Weekly

Connect with Dev Leader


BrandGhost

Powered by BrandGhost 👻