ContainerBuilder
is object that provide API to create container from its modules.
on builder creation you can provide following options:
existing container that will be used instead of new one. Please note, using this option can lead to unpredictable behavior if keys will be overridden called during async object resolution
specify what to do when dependency key that module adds already exists. Default value: throw
.
higher order function that can be used to enhance existing registrar behavior
Here is object registration api: register.<scope>(<factory>[,<monikers>])
.
(ctx: TContainer) => TObj
(ctx: TContainer, arg: TArg) => TObj
Factory function that creates object. Can contain argument that was provided on resolution.
[string | symbol]
If provided, module will be registered not only in container root, but also under monikers keys
Each time object is referenced, it will be either created or pulled from cache. Scope defines caching behavior.
Will return container object that have type of all intersecting modules.
(factory: (ctx: TContainer) => TObj): () => TObj
calls factory method on every call. You can also add argument to factory method using this signature:
(factory: (ctx: TContainer, arg: TArg) => TObj): (arg: TArg) => TObj
(waitFor: (ctr: TContainer) => Promise<TValue>, factory: (ctr: TContainer, obj: TValue) => TObj) => () => Promise<TObj>
calls factory method on every call. Waits for dependent value. It can be used to keep factory method synchronous
(factory: (ctx: TContainer) => TObj): () => TObj
calls factory method on init and then returns cached value
(value: TObj) => TObj
in oppose to other scopes, will return constant value instead of method
<TScope extends ContainerScope>(getScope: (...) => TScope, factory: (ctr) => TObj)
cache will be managed by your custom scope. You can also use argumented factory.
inAsyncScopeOf(getScope: (...) => TScope | Promise<TScope>, factory: (ctr) => TObj | Promise<TObj>)
async version of inScopeOf
. TScope
can be either sync or async. It have argumented factory support as well.
When using inAsyncScopeOf
result will always be Promise
.
{
shouldCreateNew(metadata: { arg?: any }): bool | Promise<bool>
}
Represents custom scope. It is called for scoped objects when value is saved to cache (on seconds call and later). It returns boolean flag or promise of it that determines whether or not use value from cache.