Problem guide

Reduce IServiceProvider Injection And Service Locator Usage

Use these diagnostics when you want a stronger constructor-injection culture across app code and shared libraries.

When this page is relevant

Surface hidden dependencies, service locator drift, and direct IServiceProvider injection in application code before it hardens into architecture debt.

Recommended install command

dotnet add package DependencyInjection.Lifetime.Analyzers --version 2.2.2

Relevant diagnostics

The rules that cover this failure mode

DI006

Static `IServiceProvider` Cache

`IServiceProvider` / `IServiceScopeFactory` / keyed provider stored in static fields or properties.

Severity: Warning · Code fix: Yes

DI011

`IServiceProvider` Injection

constructor injection of `IServiceProvider`, `IServiceScopeFactory`, or `IKeyedServiceProvider` in normal services.

Severity: Info · Code fix: No