DEV Community

Sachin Ghatage
Sachin Ghatage

Posted on

What’s the difference between AddScoped, AddTransient, and AddSingleton in dependency injection?

What’s the difference between AddScoped, AddTransient, and AddSingleton in dependency injection?

AddSingleton - One instance is created and shared for the entire application lifetime (across all HTTP requests).
eg)Logging,Caching

AddScoped - A new instance is created per HTTP request and shared within that same request.
eg)DbContext

AddTransient - A new instance is created every time it’s requested (even within the same HTTP request).
eg)EmailService

Top comments (0)