mardi 5 novembre 2019

Configuring .NET Core 3.0 MVC services using transient

I'm creating a Web API using .NET Core 3.0. I was adding services among which swagger and api versioning and for that i used this quick start: https://github.com/microsoft/aspnet-api-versioning/wiki/API-Documentation#aspnet-core

I noticed that they used the following line of code to configure swagger in Startup.cs:

services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();

In this case there's a seperate class (ConfigureSwaggerOptions) which defines the configuration for the swagger service. I started using this method for services that needed multiple lines of configuration.

However according to the recommendations in this article: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-3.0#default-service-container-replacement

Avoid storing data and configuration directly in the service container. Configuration should use the options pattern.

Is according to this statement, the above line of code, the wrong way to go about configuring my services?

Aucun commentaire:

Enregistrer un commentaire