The difference between AddSingleton, AddScoped and AddTransient in .NET Core

NicolasBrondinBernard

Author
@NicolasBrondinBernard

Choose your injection method carefully, or you may run into lifetime issues...

Article published on 22/07/2025, last updated on 10/08/2026

In an ASP.NET Core application, dependency injection (DI) is a core concept.

This allows you to separate responsibilities, making the code more testable and more modular.

But when registering a service in the dependency container, it's very important to carefully choose how you do it, because this will notably influence its lifetime. You'll therefore need to choose between three methods: AddSingleton, AddScoped, and AddTransient.

AddSingleton: one instance for the entire application

When using AddSingleton, only one instance of the service is created and shared for the entire lifetime of the application. It is instantiated the first time it's needed, then reused for every injection.

This type is ideal for:

  • stateless services,
  • caching,
  • shared configuration objects.
services.AddSingleton<IService, MyService>();

AddScoped: one instance per HTTP request

A service registered with AddScoped is instantiated only once per HTTP request. This means that if a service is injected multiple times within the same request, the same instance is reused.

This behavior is particularly useful for:

  • services that depend on the request context,
  • database access (e.g., DbContext),
  • any business logic tied to the duration of a request.
services.AddScoped<IRepository, MyRepository>();

AddTransient: one instance per injection

With AddTransient, a new instance is created every time the service is requested, even within the same request.

It's generally used for:

  • very lightweight services,
  • stateless helpers,
  • cases where you need completely independent objects.
services.AddTransient<IHelperService, HelperService>();

Finished reading this article?
Our complete courses
Take it to the next level with our courses!

Complete courses, exercises and certificates to really learn programming!

4.8 average rating

Comments (0)

to leave a comment

No comments yet