The interface implemented by all service containers.
- Source:
Methods
get(name) → {*}
Gets a service.
If the service was defined with a factory function, then the factory function is called and the result is returned. For performance reasons, the result of calling the factory function is cached.
If the service was defined with a value, then the value is returned.
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
- Source:
Throws:
Error If the service hasn't been defined
Returns:
- Type
- *
Example
var container = createContainer();
container.set( 'foo', true );
container.set( 'baz', ( c ) => {
if ( c.get( 'foo' ) ) {
return 'qux';
}
return 'quux';
} );
has(name) → {boolean}
Gets whether a service has been defined.
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
- Source:
Returns:
true
if the service has been defined; otherwise,
false
- Type
- boolean
set(name, factory) → {void}
Defines a service.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | |
factory |
* |
- Source:
Returns:
- Type
- void