Container Fundamentals
ClaDI container usage is centered on explicit composition roots.
Core Operations
createDIContainer(options)register(provider | provider[])resolve/resolveAsyncresolveAll/resolveAllAsyncresolveOptionalcreateScope(name?)dispose()validate()bootstrap(tokens?)lock()andisLockedexplain(token)andsnapshot()exportGraph()
Provider Shape
src/container-registration.ts
container.register({
provide: SomeToken,
lifecycle: EDependencyLifecycle.SCOPED,
deps: [DependencyToken],
useFactory: (dependency) => new Service(dependency),
});Supported strategies:
useValueuseClassuseFactoryuseExistinguseLazy
Scope Model
- Root scope owns root singleton caches.
- Child scopes inherit registrations and can add local overrides.
- Scoped providers are cached per request scope.
- Disposing a scope runs tracked cleanup callbacks in deterministic order.
Recommended Bootstrap Flow
- Create root container.
- Register all composition providers.
- Run
validate()once at startup. - Optionally run
bootstrap()to pre-warm singleton providers. - Lock root registrations with
lock()when startup wiring is complete. - Create per-request/per-job scopes.
- Dispose scopes in
finally.
Last updated on