Dotnetcore webpi dependencies injection




Think this is something i have forgotten over and over again, doing dependencies injection in Dotnet core webapi service.

All i have to to do look for this method and add whatever services that i'm going to be using :-

public void ConfigureServices(IServiceCollection services) { services.Configure(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddScoped(); // OperationService depends on each of the other Operation types.
}


What's the deal with

a) AddSingleton -> Create a single instance of object to be shared across session. The controller or services use same instance.

b) AddScoped -> Pass the same object if it is the same session

c) AddTransient -> Different object created and pass into controller and services

Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm