Scopes and Lifetime Management

Dependency Injection lifetimes in ASP.NET Core

View source code repository

Each purple DI circle is a separate place in your code where the same service is injected during one request.

Diagram explaining Singleton, Scoped, and Transient service lifetimes in ASP.NET Core

Diagram from .NET Core: Detail of Lifetime Management by Vinoth Xavier (C# Corner).

Lifetime Same instance inside request? Same across requests?
Singleton Yes Yes
Scoped Yes No
Transient No No
Service type Example
Singleton Configuration Settings View example
Scoped DbContext View example
Transient CustomService1 View example
Singleton

One instance for the entire application. Shared across all requests.

Scoped

One instance per HTTP request. Shared within that request only.

Transient

A new instance every time the service is resolved from the container.