Problem guide

Use CreateAsyncScope In Async Methods

Use this rule when background services, async handlers, or hosted-service workflows are mixing sync scopes into async disposal paths.

When this page is relevant

Catch CreateScope usage in async flows so async-disposable services are cleaned up with the correct scope pattern.

Recommended install command

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

Relevant diagnostics

The rules that cover this failure mode

DI005

Use `CreateAsyncScope` in Async Methods

`CreateScope()` used in async flows where async disposal is needed, including async methods, lambdas, local functions, anonymous methods, and top-level programs that use `await`. Detection covers regular member access (`_scopeFactory.CreateScope()`) and conditional-access receivers (`_scopeFactory?.CreateScope()`, `_provider?.CreateScope()`) alike.

Severity: Warning · Code fix: Yes