import ServiceContainer from 'ghastly/src/client/services/ServiceContainer.js'
ServiceContainer
Manages services in the application.
Constructor Summary
Public Constructor | ||
public |
Constructor. |
Member Summary
Public Members | ||
public get |
mainBindings: Iterator<string> Returns an iterator containing the main service bindings that have been registered. |
Private Members | ||
private |
The identifier aliases in this container. |
|
private |
services: StringMap<Service> The services stored in this container. |
Method Summary
Public Methods | ||
public |
bindProviders(providers: ...serviceProvider): Dispatcher Binds services to the service container via service providers. |
|
public |
construct(identifier: string | string[], builder: Function): ServiceContainer Binds a service to the container which is rebuilt each time it is fetched. |
|
public |
Fetches a service from the container, constructing it if necessary. |
|
public |
Determines if an identifier has been bound in the container. |
|
public |
instance(identifier: string | string[], value: *): ServiceContainer Binds a service to the container which is returned as a value each time it is fetched. |
|
public |
singleton(identifier: string | string[], builder: Function): ServiceContainer Binds a service to the container which is built once and cached for subsequent fetches. |
|
public |
unbind(identifier: string): ServiceContainer Removes a binding from the container, along with its aliases. |
Private Methods | ||
private |
addService(type: string, identifier: string | string[], service: *): ServiceContainer Adds a service to the container. |
|
private |
getMainBinding(alias: string): string | undefined Returns the main bound identifier for an alias. |
Public Constructors
Public Members
public get mainBindings: Iterator<string> source
Returns an iterator containing the main service bindings that have been registered.
Private Members
Public Methods
public bindProviders(providers: ...serviceProvider): Dispatcher source
Binds services to the service container via service providers.
Params:
Name | Type | Attribute | Description |
providers | ...serviceProvider | The service providers. |
Return:
Dispatcher | The instance this method was called on. |
public construct(identifier: string | string[], builder: Function): ServiceContainer source
Binds a service to the container which is rebuilt each time it is fetched.
Throw:
Thrown if the builder is not a function. |
public get(identifier: string): * source
Fetches a service from the container, constructing it if necessary.
Params:
Name | Type | Attribute | Description |
identifier | string | The identifier of the service to fetch. |
Return:
* (nullable: true) | The service requested, or |
public has(identifier: string): boolean source
Determines if an identifier has been bound in the container.
Params:
Name | Type | Attribute | Description |
identifier | string | The identifier. |
public instance(identifier: string | string[], value: *): ServiceContainer source
Binds a service to the container which is returned as a value each time it is fetched.
public singleton(identifier: string | string[], builder: Function): ServiceContainer source
Binds a service to the container which is built once and cached for subsequent fetches.
Throw:
Thrown if the builder is not a function. |
public unbind(identifier: string): ServiceContainer source
Removes a binding from the container, along with its aliases.
Params:
Name | Type | Attribute | Description |
identifier | string | The identifier or an alias for the service. |
Private Methods
private addService(type: string, identifier: string | string[], service: *): ServiceContainer source
Adds a service to the container.
Throw:
Thrown if the service type is invalid. |