Adoption guide
Roll out the analyzer with a sensible severity ladder
Use this guide when you want more NuGet installs to turn into successful team adoption instead of one-time evaluation churn.
Adoption Guide
This guide is for teams evaluating DependencyInjection.Lifetime.Analyzers for ASP.NET Core, worker-service, console, and library codebases that use Microsoft.Extensions.DependencyInjection.
What It Helps Prevent
- Captive dependencies caused by singleton-to-scoped or singleton-to-transient lifetime mismatches.
- Scope lifetime bugs such as undisposed scopes, leaked scoped services, and use-after-dispose.
- Runtime activation failures caused by missing registrations or incompatible implementation types.
- DI composition problems such as
BuildServiceProvider()misuse, duplicate/conditional registrations, and service locator patterns.
Recommended Rollout
- Install the package in one production application or shared solution layer.
- Keep the default severities for the first pass so the team can see the real signal profile.
- Promote the highest-confidence rules to
errorin.editorconfig. - Use CI to keep the agreed severity baseline enforced.
- Open focused issues for false positives or false negatives with a minimal reproduction.
Starter .editorconfig:
[*.cs]
dotnet_diagnostic.DI003.severity = error
dotnet_diagnostic.DI013.severity = error
dotnet_diagnostic.DI015.severity = warning
dotnet_diagnostic.DI016.severity = warning
dotnet_diagnostic.DI007.severity = suggestion
dotnet_diagnostic.DI011.severity = suggestion
Good First Targets
- ASP.NET Core applications that create manual scopes in background services, jobs, or startup paths.
- Solutions that rely on
IServiceProviderfactories, keyed services, orActivatorUtilities. - Codebases with intermittent
ObjectDisposedExceptionor "Unable to resolve service for type ..." production failures. - Teams that want analyzer-enforced DI standards in Rider, Visual Studio, and CI.
Evaluation Checklist
- Run
dotnet buildafter package installation and review emitted diagnostics. - Confirm whether the reported diagnostics match your intended DI architecture.
- Apply available code fixes for disposal and lifetime rewrite cases.
- Adjust
.editorconfigseverities to match how aggressively you want to enforce each rule family.
Useful Links
Reporting Gaps
When opening an issue, include:
- the affected rule ID if known
- a minimal repro snippet
- package version
- SDK version
- whether the problem is a false positive, false negative, or missing code fix