Class: Container

Container


new Container(parent, resolvers)

Private constructor. Instances are normally created with these methods:
Parameters:
Name Type Description
parent Container | undefined The optional parent container.
resolvers Array.<Resolver> | undefined The optional list of resolvers.

Methods


dispose()

Dispose of this container, releasing all references to components. Using any modifying method after this call will throw an Error. Resolve requests will be delegated to the parent container, if available.

keys(includeParent)

Obtain an array of key names known to this container and, optionally, parent containers.
Parameters:
Name Type Argument Default Description
includeParent boolean <optional>
false Include keys registered with the parent container, if any.
Returns:
A set of key names.
Type
Array

newChild(options)

Create a new child Container.
Parameters:
Name Type Description
options object Optional configuration options
Properties
Name Type Argument Default Description
inherit boolean <optional>
true When true, the new child container inherits this container's resolvers.

parent()

Obtain the parent container, or null if this container is an orphan.
Returns:
The parent container or null
Type
Container | null

register(key, component)

Register the given component with this Container, making it directly resolvable using the Container#resolve method, as well as making it available for resolution and as a potential dependency of another component.
Parameters:
Name Type Description
key String The key associated with the component.
component * The component instance that will be tracked by this container.
Throws:
  • Error if key is not a string
  • Error if component is not defined or null.
Returns:
A registration builder to configure the registration.
Type
RegistrationBuilder

resolve(key, options)

Resolve an instance for the given component key. To resolve an instance, every associated resolver is passed control and given the opportunity to create and configure the resulting component instance.

When resolving dependencies of the requested component, this same method is invoked internally for each dependency.

Parameters:
Name Type Argument Description
key string The component key with which to obtain an instance.
options Object <optional>
Configuration options.
Properties
Name Type Argument Default Description
optional boolean <optional>
false When true, in the event that the component cannot be resolved return null instead of throwing a ResolutionError.
Returns:
A promise capturing the result of the resolution. The promise will be rejected with: - Error if key is not a string. - ResolutionError if the mandatory key cannot be located. - ResolutionError if a failure occurs during the resolution process.
Type
Promise

use(resolver)

Use the given resolver middleware.
Parameters:
Name Type Description
resolver String | function The resolver to use. Supplying a String attempts to locate a standard resolver by name. Supplying a Function uses the Function itself as the resolver implementation.
See:
Returns:
this.
Type
Container