Constructor
new Container(definitions)
Instantiates the container.
Name | Type | Description |
---|---|---|
definitions |
object | mapping of service name to static service CLASS definition |
- Source:
Members
deferred_classes :Array.<*>
Array of static class definitions with deferred services. These static definitions are waiting for a service to be registered with this container so it can be injected into the prototype and instances.
- Array.<*>
- Source:
definitions :object
Static IoC item definitions from which instances are created or singleton values are returned when the items are requested. Should be mapping of item_name -> {type: Symbol, ref: *}. definition pairs.
- object
- Source:
di :boolean|module:flitter-di/src/DependencyInjector~DependencyInjector
Instance of the dependency injector this container is associated with. If this is specified, services will be injected with other services when they are instantiated.
- Source:
instances :object
Instantiated services. If a service has already been requested, it is stored here so that the single instance can be reused.
- object
- Source:
statics :object
Already injected static service definitions. These are used to resolve circular dependencies.
- object
- Source:
Methods
(private) __is_deferrable(Class) → {boolean}
Checks if a class is deferrable. That is, does it have the requirements for functioning with the defer logic. In almost all cases, these should be satisfied by having the Class extend from Injectable.
Name | Type | Description |
---|---|---|
Class |
* | the static class to check |
- Source:
- true if the class is deferrable
- Type
- boolean
(private) _process_deferral(item_name, item)
Process deferred classes that need the provided service name and instance.
Name | Type | Description |
---|---|---|
item_name |
string | the referential name of the IoC item |
item |
module:flitter-di/src/Service~Service | * | the Service or item to be injected |
- Source:
defer(Class)
Defer a static class to have its missing IoC items filled in as they become available in the service container. The class should extend from Injectable.
Name | Type | Description |
---|---|---|
Class |
* | the static class to be deferred |
- Source:
get(name) → {module:flitter-di/src/Service~Service|*}
Fetch a container item by name. It it is an injectable item, it will be injected and instantiated before return.
Name | Type | Description |
---|---|---|
name |
string | the name of the IoC item |
- Source:
- the service instance or singleton item
has(service) → {boolean}
Check if a service definition exists in this container.
Name | Type | Description |
---|---|---|
service |
string | the name of the service |
- Source:
- true if the service definition exists in this container
- Type
- boolean
proxy() → {Object}
Get the container proxy. Allows accessing IoC items by name.
- Source:
- Type
- Object
register_service(service_name, service_class)
Register a service class with the container. Allows the service to be requested and it will be instantiated and injected by the container.
Name | Type | Description |
---|---|---|
service_name |
string | |
service_class |
- Source:
register_singleton(singleton_name, value)
Register an item as a singleton with the container.
Name | Type | Description |
---|---|---|
singleton_name |
string | |
value |
* | the value tobe returned by the container |
- Source:
service(name) → {module:flitter-di/src/Service~Service|*}
Fetch a container item by name.
Name | Type | Description |
---|---|---|
name |
string |
- Deprecated:
- Please use Container.get from now on. This will be removed in the future.
- Source: