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.
#
Argumentstoken
:Token
โ a token to be bound.
#
ReturnsBinding Type syntax:
use(...tokens).from(module)
#
Uses bindings from a dependency module.
#
Argumentsuse(...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.
#
Argumentscondition
:Tag
|UnknownCreator
โ a condition.
#
Returnsbind
or use
syntax:
extend(container)
#
Sets the parent container. For more information, see Hierarchical Containers section.
#
Argumentscontainer
:Container | null
โ aContainer
ornull
that will be set as the parent container.
#
Returnsthis
โ the container.
get(token)
#
Gets a dependency bound to the token.
#
Argumentstoken
:TokenValue
โ token for which a dependence will be got.
#
ReturnsTokenType<TokenValue>
โ a dependency bound to the token.
clone()
#
Returns an unlinked clone of the container.
#
ReturnsContainer
โ new container.
#
Examplecapture()
#
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.
#
ExamplecreateContainer()
#
createContainer()
โ is alias for new Container()
.