Classes
- ObjectContainer
The Object Container is an enhanced dependency injector with support for aliases and constants, and allowing to reference classes in the application namespace by specifying their fully qualified names.
- Entry
Object container entry, representing either a class, interface, constant or an alias.
ObjectContainer
The Object Container is an enhanced dependency injector with support for aliases and constants, and allowing to reference classes in the application namespace by specifying their fully qualified names.
Kind: global class
- ObjectContainer
- new ObjectContainer(namespace)
- instance
- ._namespace :
ima.core.Namespace
- ._entries :
Map.<(string\|function(new:\*, ...\*)\|function(...\*): \*), Entry.<\*>>
- ._bindingState :
string
- ._bindingPlugin :
string
- .bind(name, classConstructor, [dependencies]) ⇒
ObjectContainer
- .constant(name, value) ⇒
ObjectContainer
- .inject(classConstructor, dependencies) ⇒
ObjectContainer
- .provide(interfaceConstructor, implementationConstructor, dependencies) ⇒
ObjectContainer
- .get(name) ⇒
T
- .getConstructorOf(name) ⇒
function
- .has(name) ⇒
boolean
- .create(name, dependencies) ⇒
T
- .clear() ⇒
ObjectContainer
- .setBindingState(bindingState, bindingPluginName)
- ._getEntry(name) ⇒
Entry.<T>
- ._updateEntryValues(classConstructor, entry, dependencies)
- ._createEntry(classConstructor, [dependencies], options) ⇒
T
- ._createInstanceFromEntry(entry, [dependencies]) ⇒
T
- ._getEntryFromConstant(compositionName) ⇒
Entry.<\*>
- ._getEntryFromNamespace(path) ⇒
Entry.<T>
- ._getEntryFromClassConstructor(classConstructor) ⇒
Entry.<T>
- ._namespace :
- static
- .PLUGIN_BINDING_STATE ⇒
string
- .IMA_BINDING_STATE ⇒
string
- .APP_BINDING_STATE ⇒
string
- .PLUGIN_BINDING_STATE ⇒
new ObjectContainer(namespace)
Initializes the object container.
Param | Type | Description |
---|---|---|
namespace | ima.core.Namespace |
The namespace container, used to access classes and values using their fully qualified names. |
objectContainer._namespace : ima.core.Namespace
The namespace container, used to access classes and values using their fully qualified names.
Kind: instance property of ObjectContainer
objectContainer._entries : Map.<(string\|function(new:\*, ...\*)\|function(...\*): \*), Entry.<\*>>
Kind: instance property of ObjectContainer
objectContainer._bindingState : string
The current binding state.
The {@linkcode setBindingState()} method may be called for changing object container binding state only by the bootstrap script.
Kind: instance property of ObjectContainer
objectContainer._bindingPlugin : string
The current plugin binding to OC.
The {@linkcode setBindingState()} method may be called for changing object container binding state only by the bootstrap script.
Kind: instance property of ObjectContainer
objectContainer.bind(name, classConstructor, [dependencies]) ⇒ ObjectContainer
Binds the specified class or factory function and dependencies to the specified alias. Binding a class or factory function to an alias allows the class or function to be specied as a dependency by specifying the alias and creating new instances by referring to the class or function by the alias.
Also note that the same class or function may be bound to several aliases and each may use different dependencies.
The alias will use the default dependencies bound for the class if no dependencies are provided.
Kind: instance method of ObjectContainer
Returns: ObjectContainer
- This object container.
Param | Type | Description |
---|---|---|
name | string |
Alias name. |
classConstructor | function | function |
The class constructor or a factory function. |
[dependencies] | Array.<\*> |
The dependencies to pass into the constructor or factory function. |
objectContainer.constant(name, value) ⇒ ObjectContainer
Defines a new constant registered with this object container. Note that
this is the only way of passing string
values to constructors
because the object container treats strings as class, interface, alias
or constant names.
Kind: instance method of ObjectContainer
Returns: ObjectContainer
- This object container.
Param | Type | Description |
---|---|---|
name | string |
The constant name. |
value | \* |
The constant value. |
objectContainer.inject(classConstructor, dependencies) ⇒ ObjectContainer
Configures the object loader with the specified default dependencies for the specified class.
New instances of the class created by this object container will receive the provided dependencies into constructor unless custom dependencies are provided.
Kind: instance method of ObjectContainer
Returns: ObjectContainer
- This object container.
Param | Type | Description |
---|---|---|
classConstructor | function |
The class constructor. |
dependencies | Array.<\*> |
The dependencies to pass into the constructor function. |
objectContainer.provide(interfaceConstructor, implementationConstructor, dependencies) ⇒ ObjectContainer
Configures the default implementation of the specified interface to use when an implementation provider of the specified interface is requested from this object container.
The implementation constructor will obtain the provided default
dependencies or the dependencies provided to the create()
method.
Kind: instance method of ObjectContainer
Returns: ObjectContainer
- This object container.
Param | Type | Description |
---|---|---|
interfaceConstructor | function |
The constructor of the interface representing the service. |
implementationConstructor | function |
The constructor of the class implementing the service interface. |
dependencies | Array.<\*> |
The dependencies to pass into the constructor function. |
objectContainer.get(name) ⇒ T
Retrieves the shared instance or value of the specified constant, alias, class or factory function, interface, or fully qualified namespace path (the method checks these in this order in case of a name clash).
The instance or value is created lazily the first time it is requested.
Kind: instance method of ObjectContainer
Returns: T
- The shared instance or value.
Param | Type | Description |
---|---|---|
name | string | function | function |
The name of the alias, class, interface, or the class, interface or a factory function. |
objectContainer.getConstructorOf(name) ⇒ function
Returns the class constructor function of the specified class.
Kind: instance method of ObjectContainer
Returns: function
- The constructor function.
Param | Type | Description |
---|---|---|
name | string | function |
The name by which the class is registered with this object container. |
objectContainer.has(name) ⇒ boolean
Returns true
if the specified object, class or resource is
registered with this object container.
Kind: instance method of ObjectContainer
Returns: boolean
- true
if the specified object, class or
resource is registered with this object container.
Param | Type | Description |
---|---|---|
name | string | function |
The resource name. |
objectContainer.create(name, dependencies) ⇒ T
Creates a new instance of the class or retrieves the value generated by the factory function identified by the provided name, class, interface, or factory function, passing in the provided dependencies.
The method uses the dependencies specified when the class, interface or factory function has been registered with the object container if no custom dependencies are provided.
Kind: instance method of ObjectContainer
Returns: T
- Created instance or generated value.
Param | Type | Description |
---|---|---|
name | string | function | function |
The name of the alias, class, interface, or the class, interface or a factory function to use. |
dependencies | Array.<\*> |
The dependencies to pass into the constructor or factory function. |
objectContainer.clear() ⇒ ObjectContainer
Clears all entries from this object container and resets the locking mechanism of this object container.
Kind: instance method of ObjectContainer
Returns: ObjectContainer
- This object container.
objectContainer.setBindingState(bindingState, bindingPluginName)
Kind: instance method of ObjectContainer
Param | Type | Default |
---|---|---|
bindingState | string |
|
bindingPluginName | string |
null |
objectContainer._getEntry(name) ⇒ Entry.<T>
Retrieves the entry for the specified constant, alias, class or factory function, interface, or fully qualified namespace path (the method checks these in this order in case of a name clash).
The method retrieves an existing entry even if a qualified namespace path is provided (if the target class or interface has been configured in this object container).
The method throws an Error
if no such constant, alias,
registry, interface implementation is known to this object container and
the provided identifier is not a valid namespace path specifying an
existing class, interface or value.
Kind: instance method of ObjectContainer
Returns: Entry.<T>
- The retrieved entry.
Throws:
Error
If no such constant, alias, registry, interface implementation is known to this object container.
Param | Type | Description |
---|---|---|
name | string | function |
Name of a constant or alias, factory function, class or interface constructor, or a fully qualified namespace path. |
objectContainer._updateEntryValues(classConstructor, entry, dependencies)
The method update classConstructor and dependencies for defined entry. The entry throw Error for constants and if you try override dependencies more than once.
Kind: instance method of ObjectContainer
Param | Type | Description |
---|---|---|
classConstructor | function | function |
The class constructor or factory function. |
entry | Entry |
The entry representing the class that should have its instance created or factory faction to use to create a value. |
dependencies | Array.<\*> |
The dependencies to pass into the constructor or factory function. |
objectContainer._createEntry(classConstructor, [dependencies], options) ⇒ T
Creates a new entry for the provided class or factory function, the provided dependencies and entry options.
Kind: instance method of ObjectContainer
Returns: T
- Created instance or generated value.
Param | Type | Description |
---|---|---|
classConstructor | function | function |
The class constructor or factory function. |
[dependencies] | Array.<\*> |
The dependencies to pass into the constructor or factory function. |
options | Object |
objectContainer._createInstanceFromEntry(entry, [dependencies]) ⇒ T
Creates a new instance of the class or retrieves the value generated by the factory function represented by the provided entry, passing in the provided dependencies.
The method uses the dependencies specified by the entry if no custom dependencies are provided.
Kind: instance method of ObjectContainer
Returns: T
- Created instance or generated value.
Param | Type | Default | Description |
---|---|---|---|
entry | Entry.<T> |
The entry representing the class that should have its instance created or factory faction to use to create a value. | |
[dependencies] | Array.<\*> |
[] |
The dependencies to pass into the constructor or factory function. |
objectContainer._getEntryFromConstant(compositionName) ⇒ Entry.<\*>
Retrieves the constant value denoted by the provided fully qualified composition name.
The method returns the entry for the constant if the constant is registered
with this object container, otherwise return null
.
Finally, if the constant composition name does not resolve to value,
the method return null
.
Kind: instance method of ObjectContainer
Returns: Entry.<\*>
- An entry representing the value at the specified
composition name in the constants. The method returns null
if the specified composition name does not exist in the constants.
Param | Type |
---|---|
compositionName | string |
objectContainer._getEntryFromNamespace(path) ⇒ Entry.<T>
Retrieves the class denoted by the provided fully qualified name within the application namespace.
The method then checks whether there are dependecies configured for the class, no matter whether the class is an implementation class or an “interface” class.
The method returns the entry for the class if the class is registered with this object container, otherwise an unregistered entry is created and returned.
Finally, if the namespace path does not resolve to a class, the method return an unregistered entry resolved to the value denoted by the namespace path.
Alternatively, if a constructor function is passed in instead of a
namespace path, the method returns null
.
Kind: instance method of ObjectContainer
Returns: Entry.<T>
- An entry representing the value or class at the
specified path in the namespace. The method returns null
if the specified path does not exist in the namespace.
Param | Type | Description |
---|---|---|
path | string | function |
Namespace path pointing to a class or a value in the application namespace, or a constructor function. |
objectContainer._getEntryFromClassConstructor(classConstructor) ⇒ Entry.<T>
Retrieves the class denoted by the provided class constructor.
The method then checks whether there are defined $dependecies
property for class. Then the class is registered to this object
container.
The method returns the entry for the class if the specified class
does not have defined $dependencies
property return
null
.
Kind: instance method of ObjectContainer
Returns: Entry.<T>
- An entry representing the value at the specified
classConstructor. The method returns null
if the specified classConstructor does not have defined
$dependencies
.
Param | Type |
---|---|
classConstructor | function |
ObjectContainer.PLUGIN_BINDING_STATE ⇒ string
Returns constant for plugin binding state.
When the object container is in plugin binding state, it is impossible to register new aliases using the {@linkcode bind()} method and register new constant using the {@linkcode constant()} method, or override the default class dependencies of any already-configured class using the {@linkcode inject()} method (classes that were not configured yet may be configured using the {@linkcode inject()} method or {@linkcode provide()} method).
This prevents the unpriviledged code (e.g. 3rd party plugins) from overriding the default dependency configuration provided by ima, or overriding the configuration of a 3rd party plugin by another 3rd party plugin.
The application itself has always access to the unlocked object container.
Kind: static property of ObjectContainer
Returns: string
- The plugin binding state.
ObjectContainer.IMA_BINDING_STATE ⇒ string
Returns constant for IMA binding state.
When the object container is in ima binding state, it is possible to register new aliases using the {@linkcode bind()} method and register new constant using the {@linkcode constant()} method, or override the default class dependencies of any already-configured class using the {@linkcode inject()} method (classes that were not configured yet may be configured using the {@linkcode inject()} method or {@linkcode provide()} method).
Kind: static property of ObjectContainer
Returns: string
- The IMA binding state.
ObjectContainer.APP_BINDING_STATE ⇒ string
Returns constant for app binding state.
When the object container is in app binding state, it is possible to register new aliases using the {@linkcode bind()} method and register new constant using the {@linkcode constant()} method, or override the default class dependencies of any already-configured class using the {@linkcode inject()} method (classes that were not configured yet may be configured using the {@linkcode inject()} method or {@linkcode provide()} method).
Kind: static property of ObjectContainer
Returns: string
- The app binding state.
Entry
Object container entry, representing either a class, interface, constant or an alias.
Kind: global class
- Entry
- new Entry(classConstructor, [dependencies], referrer, [options])
- .classConstructor :
function
|function
- .sharedInstance :
T
- ._options :
Object
- ._referrer :
string
- ._dependencies :
Array.<\*>
- ._overrideCounter :
number
new Entry(classConstructor, [dependencies], referrer, [options])
Initializes the entry.
Param | Type | Default | Description |
---|---|---|---|
classConstructor | function | function |
The class constructor or constant value getter. | |
[dependencies] | Array.<\*> |
[] |
The dependencies to pass into the constructor function. |
referrer | string |
Reference to part of application that created this entry. | |
[options] | Object |
The Entry options. |
entry.classConstructor : function
| function
The constructor of the class represented by this entry, or the getter of the value of the constant represented by this entry.
Kind: instance property of Entry
entry.sharedInstance : T
The shared instance of the class represented by this entry.
Kind: instance property of Entry
entry._options : Object
The Entry options.
Kind: instance property of Entry
entry._referrer : string
Reference to part of application that created this entry.
Kind: instance property of Entry
entry._dependencies : Array.<\*>
Dependencies of the class constructor of the class represented by this entry.
Kind: instance property of Entry
entry._overrideCounter : number
The override counter
Kind: instance property of Entry