Utility Functions
@brushy/di provides several utility functions to facilitate the use of the dependency injection system in different contexts.
Typed tokens
UsecreateToken<T>() to create tokens with automatic type inference in register, resolve, inject, and useInject.
Import
Basic usage
Class as token
defineModule
Symbol / string) still work but require a manual generic: resolve<MyType>(TOKEN).
Request Scope (AsyncLocalStorage)
On Node.js,@brushy/di binds the active HTTP request scope with AsyncLocalStorage. Scoped dependencies resolve automatically inside that scope.
Import
Express middleware
Scripts and tests
isRequestScopeSupported() to detect Node.js ALS. On React Native, pass an explicit scope in InjectOptions or use BrushyDIProvider context.
resolve
Theresolve function allows resolving dependencies globally, without needing to directly access the container.
Import
Basic Usage
With Scope
inject
Theinject object provides utilities for dependency injection in any context.
Import
Global Container Configuration
Dependency Resolution
cache
Thecache object provides utilities for managing promise caching.
Import
Clear Cache
monitor
Themonitor object provides utilities for monitoring and observing container behavior.
Import
Create Monitor
BrushyDIProvider
TheBrushyDIProvider component is used to provide a DI container to React components.