Figure 04: Transient lifetime services are created each time they are requested from the service container
Each time a service is requested, a new instance will be created. This is the most common and always the safest option if you are worried about multithreading.
If we inject the same service into a Controller and a View in an MVC application, two different instances will be created in the controller and the view.
How to register the transient service .NET Core during startup.
public void ConfigureServices(IServiceCollection services)
{ services.AddTransient();
}
“In terms of the lifetime of the instance, the Singleton object gets the highest life per instantiation, followed by a Scoped service object and the least by a Transient object.”
Written by