Tuesday, 25 May 2021

startup in azure


In .NET's dependency injection there are three major lifetimes:


1) Singleton which creates a single instance throughout the application. It creates the instance for the first time and reuses the same object in the all calls.


2) Scoped lifetime services are created once per request within the scope. It is equivalent to a singleton in the current scope. For example, in MVC it creates one instance for each HTTP request, but it uses the same instance in the other calls within the same web request.


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


 1)Transient objects are always different; a new instance is provided to every controller and every service.


2)Scoped objects are the same within a request, but different across different requests.


3)Singleton objects are the same for every object and every request.

No comments:

Post a Comment