Singleton
Usesingleton for stateless services or process-wide dependencies.
- loggers
- configuration readers
- pure policies
- stateless mappers
Scoped
Usescoped for dependencies that should be reused within one request or unit of work.
- request context
- repositories bound to a request transaction
- DataLoader instances
- request-local caches
Transient
Usetransient when every resolution should create a fresh instance.
Request scopes
In web frameworks, a request scope is created when the request starts and disposed when the request finishes.Child scopes
v2.1+ addsscope.createChildScope() for nested units of work inside one request (for example a
GraphQL subscription operation or a sub-task that should share parent scoped services).
- Dispose child scopes before the parent (
ScopeHasActiveChildrenErrorotherwise). - Child scopes can read parent
set()values and parent scoped instances. - New scoped instances created in a child are stored on that child only.
Lifetime validation
Wyrly can validate lifetime relationships. For example, a singleton should not depend on a scoped dependency — directly or transitively — because that would capture request-specific state in a process-wide instance. Validation also warns whenregister() overrides @Injectable deps or lifetime metadata.
Run validation as part of test or CI: