What is the difference between services.AddTransient, service.AddScoped and service.AddSingleton methods in ASP.NET Core?


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.

Refs:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.2#service-lifetimes-and-registration-options
https://stackoverflow.com/questions/38138100/what-is-the-difference-between-services-addtransient-service-addscoped-and-serv

Leave a Comment