Skip to main content
Request scope binds scoped lifecycle providers to a single unit of work, typically one HTTP request on Node.js.

Support detection

In browsers and React Native, runInRequestScope still runs the callback but scoped resolution uses explicit scope objects when ALS is unavailable.

Express / Connect middleware

brushyRequestScope creates a unique scope per request and clears scoped instances when the response finishes.

Options

Manual scope (scripts & tests)

RequestScopeOptions

object
Custom scope key. Auto-generated when omitted.
Container
Container to clean up. Defaults to registry default.
(scope) => void
Called when scope is entered.
() => void
Custom cleanup instead of clearRequestScope.
boolean
default:"false"
Skip automatic scope cleanup on exit.

getActiveScope

containerRegistry.getContainer() uses the active scope to pick scoped containers when registered.

Register scoped services

Fastify & async handlers

Use runInRequestScopeAsync inside route handlers when middleware is not available:
See also Server utilities.