Dependencies Service Lifetimes and Registration Options

ASP.NET services can be configured with the following lifetimes:

Transient

Transient lifetime services are created each time they are requested. This lifetime works best for lightweight, stateless services.

services.AddTransient<ICampRepository, CampRepository>();

Scoped

Scoped lifetime services are created once per request.

services.AddScoped<ICampRepository, CampRepository>();

Singleton

Singleton lifetime services are created the first time they are requested and then every subsequent request will use the same instance.

services.AddSingleton(_config);

results matching ""

    No results matching ""