Problem guide

Avoid BuildServiceProvider In ConfigureServices

Use these rules when you want to stop BuildServiceProvider misuse during registration while still allowing intentional provider factory methods.

When this page is relevant

Catch BuildServiceProvider misuse during service registration so composition code does not silently create a second service container.

Recommended install command

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

Relevant diagnostics

The rules that cover this failure mode

DI016

BuildServiceProvider Misuse

`BuildServiceProvider()` calls while composing registrations (for example in `ConfigureServices`, `IServiceCollection` extension registration methods, registration lambdas, or builder-style `.Services` helper flows).

Severity: Warning · Code fix: No

DI014

Root Service Provider Not Disposed

root providers from `BuildServiceProvider()` that are never disposed, including local providers whose only manual disposal is conditional, catch-only, after reassignment to another provider, or after repeated creation inside a loop.

Severity: Warning · Code fix: Yes