April 23, 2024


The Internet Generation

How to use the options pattern in ASP.NET Core

When working in ASP.Web Core you will frequently specify your application’s configurations, retail store them in some file, and then retrieve these configurations when the application needs them. Normally, you would sign-up your dependencies in the ConfigureServices strategy of the Startup course. You can specify your application’s configurations in the appsettings.json or some other .json file and then choose benefit of dependency injection by IOptions to go through these configurations in your application.

The solutions designs provide an elegant way to add strongly typed configurations to your ASP.Web Core application. The solutions sample, which is an extension on prime of the IServiceCollection interface, will take benefit of lessons to characterize a team of associated configurations. This post talks about the solutions sample, why it is valuable, and how it can be utilised for working with configuration information in ASP.Web Core.

To work with the code examples furnished in this post, you should really have Visual Studio 2019 set up in your technique. If you never previously have a duplicate, you can down load Visual Studio 2019 listed here.

Produce an ASP.Web Core API venture

Initially off, let’s develop an ASP.Web Core venture in Visual Studio. Assuming Visual Studio 2019 is set up in your technique, follow the steps outlined under to develop a new ASP.Web Core API venture in Visual Studio.