Rules

Rule index

Browse all analyzer rules with rule summaries, README examples, and extracted sample-app snippets.

DI001

Service Scope Not Disposed

`IServiceScope` instances created with `CreateScope()` or `CreateAsyncScope()` that are never disposed.

Severity: Warning · Code fix: Yes

DI002

Scoped Service Escapes Scope

a service resolved from a scope that is returned or stored somewhere longer-lived.

Severity: Warning · Code fix: Yes

DI003

Captive Dependency

singleton services capturing scoped or transient dependencies, including constructor injection and high-confidence factory paths such as inline delegates, method-group factories, keyed resolutions, and `ActivatorUtilities.CreateInstance(...)` without explicit constructor arguments.

Severity: Warning · Code fix: Yes

DI006

Static `IServiceProvider` Cache

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

Severity: Warning · Code fix: Yes

DI008

Disposable Transient Service

transient services implementing `IDisposable`/`IAsyncDisposable` in risky patterns.

Severity: Warning · Code fix: Yes

DI011

`IServiceProvider` Injection

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

Severity: Info · Code fix: No

DI013

Implementation Type Mismatch

invalid `typeof` service/implementation pairs that compile but fail at runtime.

Severity: Error · Code fix: No

DI015

Unresolvable Dependency

registered services with direct or transitive constructor/factory dependencies that are not registered (including keyed and open-generic paths).

Severity: Warning · Code fix: Yes

DI016

BuildServiceProvider Misuse

`BuildServiceProvider()` calls while composing registrations (for example in `ConfigureServices`, `IServiceCollection` extension registration methods, or registration lambdas).

Severity: Warning · Code fix: No