Class: ObjectManager

ObjectManager(options)

The ObjectManager is the central component which instantiates modules, which may be requested by other objects. The ObjectManager works with dependency trees. Each dependency tree has an identifier. The default tree has the identifier "root". If you need a different tree or want to branch the tree so the depending instances have a different set of dependencies, you need either need to call the requestInstance method with a different treeIdentifier or you define the treeIdentifier in the dependency definition of your module.

To request an instance, just call getInstance(moduleName)

Constructor

new ObjectManager(options)

Parameters:
Name Type Description
options Object

The configuration options

Properties
Name Type Attributes Default Description
moduleSrc Array

An array with paths to the module source files to autowire

cacheFile String <optional>

A file to use as a cache for the module meta data

configurations Object <optional>

A set of configurations to use

globalScope boolean <optional>
false

When set to true, will register the current instance in the global scope and return it, when requested again. Use this only when necessary and you need to use the object manager in different locations that cannot be resolved in one scope by the ObjectManager

Author:
  • Wolfgang Felbermeier (@f3lang)
Source:

Methods

addConfiguration(config, rootopt)

Adds a configuration to the Object Manager

Parameters:
Name Type Attributes Description
config object

The configuration object

root String <optional>

The configuration root, that can be used to inject settings.

Source:

addDependencyTree(root)

Adds a new dependency tree to the stack

Parameters:
Name Type Description
root string

The name of the tree

Source:

connectObjectManager(objectManager)

Connect another object manager to this instance. Local resolvable modules will have precedence before modules of additional object managers.

Parameters:
Name Type Description
objectManager ObjectManager

The object manager to connect

Source:

getConfigInjector(configurationIdentifier) → {Object}

Generates an injector definition for a configuration setting.

Parameters:
Name Type Description
configurationIdentifier string

The configuration identifier of the module

Source:
Returns:
Type
Object

getContainingObjectManager(moduleName) → {ObjectManager}

Get the object manager which can create an instance of the module. If no available object manager including this instance can resolve the module, nothing is returned.

Parameters:
Name Type Description
moduleName string
Source:
Returns:
Type
ObjectManager

getInjectionConfiguration(moduleName) → {InjectionConfiguration}

Returns the injection configuration of a module

Parameters:
Name Type Description
moduleName String

The name of the module

Source:
Returns:
Type
InjectionConfiguration

getInstance(moduleName, treeopt) → {*}

Returns an instance of a module by name. All dependencies will be injected.

Parameters:
Name Type Attributes Description
moduleName string

The name of the module. Must match the Module name or one of its alias

tree string <optional>

The tree to use. Defaults to "root"

Source:
Returns:

The instance of the module

Type
*

getInstantiator(name) → {AbstractInstantiator}

Parameters:
Name Type Description
name String

The Name of the instantiator

Source:
Returns:
Type
AbstractInstantiator

getModuleInjector(moduleIdentifier) → {Object}

Generates an injector definition for the injection of a module

Parameters:
Name Type Description
moduleIdentifier string

The module identifier

Source:
Returns:
Type
Object

getModuleParams(injectors, root, requestId) → {*|Object|Uint8Array|Array.<any>|Int32Array|Uint16Array}

Will resolve all instances and configurations needed to instantiate a module.

Parameters:
Name Type Description
injectors Array

The injector definitions to resolve

root string

The tree to request the injectable parameters from

requestId string

The unique requestId to discover circular dependencies

Source:
Returns:
Type
* | Object | Uint8Array | Array.<any> | Int32Array | Uint16Array

registerInstantiator(name, instantiator)

Registers a new Instantiator

Parameters:
Name Type Description
name string

The id which this instantiator is used with.

instantiator AbstractInstantiator

An instance of the instantiator

Source:

requestInstanceOfModule(moduleName, treeIdentifieropt, _requestIdopt) → {*}

Requests an instance of a module. All dependencies will be injected also into submodules.

Parameters:
Name Type Attributes Default Description
moduleName string

The name of the module. Must match the Module name or one of its alias

treeIdentifier string <optional>
root

The tree to use. Default is "root"

_requestId int <optional>

Internal parameter to detect circular dependencies

Source:
Returns:
Type
*