IHttpContextAccessor stores the current context in an AsyncLocal, so it flows with the request's async calls and is valid only while the request runs. Fire-and-forget work, Task.Run that outlives the request, or a singleton reading it later can see null or a recycled context from another request, because HttpContext objects are pooled. HttpContext is also not thread-safe: reading or writing it from parallel tasks, even during the request, can race and corrupt state. Don't capture scoped services (like a DbContext) either; they are disposed when the request scope ends. Instead, copy the values you need (user ID, correlation ID, tenant) into a message or parameters before starting the work, create a new DI scope in the background worker, and use a queue (Channel<T> with a BackgroundService) for anything that must outlive the request.
Checks they understand the request lifetime and AsyncLocal flow
Last updated 23 Nov 2026.