Problem guide

Find Captive Dependencies In ASP.NET Core

This page is for teams searching for captive dependency detection in ASP.NET Core, worker services, and generic-host apps.

When this page is relevant

Use compile-time diagnostics to catch singleton-to-scoped and singleton-to-transient lifetime mismatches before stale state or thread-safety bugs ship.

Recommended install command

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

Relevant diagnostics

The rules that cover this failure mode

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