When this page is relevant
Compile-time guidance for scope leaks, services escaping scopes, and using resolved services after the scope ends in ASP.NET Core and .NET apps.
Problem guide
These diagnostics catch the most common scope-lifetime mistakes that lead to disposed-service failures in background jobs, middleware, and startup code.
When this page is relevant
Compile-time guidance for scope leaks, services escaping scopes, and using resolved services after the scope ends in ASP.NET Core and .NET apps.
Recommended install command
dotnet add package DependencyInjection.Lifetime.Analyzers --version 2.2.2
Relevant diagnostics
DI001
`IServiceScope` instances created with `CreateScope()` or `CreateAsyncScope()` that are never disposed.
DI002
a service resolved from a scope that is returned or stored somewhere longer-lived.
DI004
using a service after the scope that produced it has already ended.
DI014
root providers from `BuildServiceProvider()` that are never disposed.