ultimatekeron.blogg.se

Asp net monitor
Asp net monitor






public class M圜ontroller : ControllerBase Then, you can register your custom configuration class (in this example, MyOptions) to be bound to a specific section in appsettings.json (in this example, "myOptions").

asp net monitor

In order to use the options pattern in your API, you’ll first need to add the options services to the container using the services.AddOptions() method.

Asp net monitor how to#

In this article I’ll explain how to set up an ASP.NET Core 5.0 API to run custom code whenever changes are made to appsettings.json. One use case for this functionality would be if you wanted to maintain a list in the config file, and log every time that list was changed. However, if you request your configuration using IOptionsMonitor, you get the ability to define a lambda function to run every time appsettings.json is changed. While this works just fine in some cases, it doesn’t allow you to actually run code when the configuration is changed. In your controllers, you can request the configuration class T as a dependency by using an options wrapper class like IOptions. That is, you create a model class that has a field for each property in your config file, and then set up the application to map the configuration to that class, which can be injected into controllers and services.

asp net monitor

Did you know you can directly respond to config file changes in ASP.NET Core? By using the IOptionsMonitor interface, it’s possible to run a lambda function every time a config file is updated.įor those who aren’t too familiar with it, ASP.NET Core configuration is handled using the Options Pattern.






Asp net monitor