API
Everything exported by @navios/di and @navios/di/testing. Each entry links to the page that explains it; this page only lists signatures.
Containers
Container
Container is itself injectable: inject(Container) returns the root container.
ScopedContainer
Created by container.createScope(). It has get, getSync, peek, addInstance, isRegistered, invalidate, onInvalidate, ready, dispose and [Symbol.asyncDispose] with the signatures above, and adds:
addInstance() on a scope stores a request-scoped value. A scope has no provide(), decorate() or getProvider(); those belong to the root.
inject(ScopedContainer) returns the current scope in a request-scoped service.
IContainer
The interface both containers implement: get, getSync, peek, invalidate, onInvalidate, isRegistered, addInstance, dispose, ready. It is the type of FactoryContext.container.
Registration
Only a registration on the class itself counts. An undecorated subclass of an injectable class has no token.
Option types: InjectableOptions, FactoryOptions, RegisterInjectableOptions, RegisterFactoryOptions, RegisterProviderOptions, ContainerOptions. ClassType is any class, ClassTypeWithInstance<T> one whose instances are a T, and ResolvedInstance<C> what a class resolves to: its instance, or the product of a factory class.
Injection functions
All three can only be called while a class or factory is being built, before its first await. See Services and injection.
Each takes (token, args?). Their overloads are exported as the types SyncResolve, OptionalResolve and AsyncResolve; container.getSync, container.peek and container.get share them, and so does ctx.inject the last. When a token requires arguments and none are given, the return type is the string type MissingArgsError<S>, which names the missing keys.
Tokens
See Tokens.
Factories and lifecycle
InjectableScope
See Scopes.
Schema types
@navios/di contains its own copy of the Standard Schema types, so it depends on no schema library.
Error codes
Every failure raised by the container is a DIError. What a decorator, an onInvalidate listener or other code of yours throws outside a construction is passed on as it is.
An error never carries the arguments of a token, which may hold secrets and would end up in logs.
The messages, for matching against logs. In code, compare code.
AccessBeforeInit is thrown inside a construction pass that the container discards and repeats, so it is seen only by code that catches it in the constructor or keeps the placeholder and uses it later.
Testing
Exported from @navios/di/testing. See Testing.
TestContainer
Extends Container.
UnitTestContainer
Extends Container in strict mode. Objects returned by get() and getSync(), of the container and of its scopes, record their method calls.
Testing types
BindingBuilder<T>, ProviderConfig<T>, TestContainerOptions, UnitTestContainerOptions, MethodCallRecord ({ method, args, timestamp, result?, error? }), LifecycleRecord ({ event, timestamp, instanceName }), MockServiceStats, DependencyNode, DependencyGraph.