What is AddSingleton, AddScoped and AddTransient method?

 v AddTransient instance will not be shared at all, even with in the same request. Every time a new instance will be created.

v AddSingleton method create only one instance when the service is requested for first time. And then the same instance will be shared by all different http requests.

v   AddScoped method create single instance per request. For every individual request there will be a single instance or object.

v AddTransient instance will not be shared at all, even with in the same request. Every time a new instance will be created.

 


v The Service Lifetime refers to the lifespan of a registered service. Or
The service lifetime controls how long a result object will live for after it has been created by the container.

Post a Comment

Previous Post Next Post