Container
Container is a Brandi class whose instances store information about dependencies,
resolve dependencies, and inject dependencies into targets.
Container Methods#
bind(token)#
Binds the token to an implementation.
Arguments#
token:Tokenโ a token to be bound.
Returns#
Binding Type syntax:
use(...tokens).from(module)#
Uses bindings from a dependency module.
Arguments#
use(...tokens)#
...tokens:Token[]โ tokens to be used from a dependency module.
use(...tokens).from(module)#
module:DependencyModuleโ a dependency module.
when(condition)#
Creates a conditional binding.
Arguments#
condition:Tag|UnknownCreatorโ a condition.
Returns#
bind or use syntax:
extend(container)#
Sets the parent container. For more information, see Hierarchical Containers section.
Arguments#
container:Container | nullโ aContainerornullthat will be set as the parent container.
Returns#
this โ the container.
get(token)#
Gets a dependency bound to the token.
Arguments#
token:TokenValueโ token for which a dependence will be got.
Returns#
TokenType<TokenValue> โ a dependency bound to the token.
clone()#
Returns an unlinked clone of the container.
Returns#
Container โ new container.
Example#
capture()#
Captures (snapshots) the current container state.
note
The capture() method works only in development mode (process.env.NODE_ENV !== 'production').
Container.capture is undefined in production mode.
restore()#
Restores the captured container state.
note
The restore() method works only in development mode (process.env.NODE_ENV !== 'production').
Container.restore is undefined in production mode.
Example#
createContainer()#
createContainer() โ is alias for new Container().