When this page is relevant
Catch BuildServiceProvider misuse during service registration so composition code does not silently create a second service container.
Problem guide
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.18.24
Relevant diagnostics
DI016
`BuildServiceProvider()` calls while composing registrations (for example in `ConfigureServices`, `IServiceCollection` extension registration methods, registration lambdas, or builder-style `.Services` helper flows), whether written as reduced extension syntax (`services.BuildServiceProvider()`) or as a direct static call (`ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(builder.Services)`).
DI014
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. Straight-line explicit disposal, standard `Dispose()` to `Dispose(true)` cleanup, and caller-owned return flows are accepted even when the `BuildServiceProvider()` result is parenthesized, same-instance cast, null-forgiven, selected by a ternary arm, or supplied by a null-coalescing operand; user-defined conversions remain reportable because they may produce a different instance.