Every provider declares a lifecycle that controls instance caching and sharing.
Lifecycle types
Scoped dependencies
scoped resolves against the active request scope (AsyncLocalStorage on Node) or an explicit scope object:
See Request scope and Scoped containers.
Singleton TTL
Optional ttl (milliseconds) expires cached singletons lazily on the next resolve:
Immutable integrity
immutable providers are cached permanently. In development, verifyImmutableIntegrity() returns a checker that warns if the same token resolves to different object references:
Garbage collector
Evict idle scoped/singleton wrappers from internal caches:
Useful for long-running servers with many ephemeral scope keys.
Cache invalidation
Clears the resolver cache for a token and resets the container’s last-resolve micro-cache.
Parent containers
Child containers inherit unresolved tokens from parent. Register overrides on the child; resolves fall through to the parent when the token is not local.
Choosing a lifecycle
API servers: singleton for infrastructure, scoped for per-request services, transient for cheap stateless objects.
React client: Usually singleton for services. Use scoped only when mirroring server request isolation in tests.