Class: Container

'brixy.di.Container'~ Container

new Container ()

Dependency injection container.

Source:

Methods

getInstance (subject, injectionopt) → {Object}

Returns the instance of the subject.
In case of creating a new instance, it injects all dependencies that are specified by the SubjectType.injection property.
Optionally the injection argument may replace some of them.

Types of the subject:

  1. service name: creates/returns instance of the service (injection argument is not applied)
  2. module name: property module.Me is used as constructor of a new instance
  3. function: is used as constructor of a new instance
  4. object: is returned unchanged (injection argument is not applied)
Parameters:
Name Type Attributes Description
subject *

Service name or module name or constructor function or subject instance.

injection Array <optional>

Forced injection. Defined members will replace the corresponding Type.injection members. Not applicable for the service or object. (optional)

Throws:
  • Exception

Returns:
  • Object :
    • Instance of the subject.
Source:

getService (name) → {Object}

Returns a service object.

Parameters:
Name Type Description
name string

Service name.

Throws:
  • Exception

Returns:
  • Object
Source:

instanceByName (name, injectionopt) → {Object}

Creates the instance of the service or module. Injects all dependencies that are specified by the Type.injection property. Optionally, in case of module name, the injection argument may replace some of them.

Parameters:
Name Type Attributes Description
name string

Service or module name.

injection Array <optional>

Forced injection. Defined members will replace the corresponding Type.injection members. Not applicable for the service. (optional)

Throws:
  • Exception

Returns:
  • Object :
    • Service or module instance.
Source:

instanceByType (Type, injectionopt) → {Object}

Creates the instance of the Type. Injects all dependencies that are specified by Type.injection property. Optionally the injection argument may replace some of them.

Parameters:
Name Type Attributes Description
Type function

Constructor.

injection Array <optional>

Forced injection. Defined members will replace the corresponding Type.injection members. (optional)

Throws:
  • Exception

Returns:
  • Object :
    • Instance of the Type.
Source:

registerService (name, service)

Registers new service.

Parameters:
Name Type Description
name string

Service name.

service *

Module name (module.Me must refer to the object constructor) or service name or config object or service object.

Throws:
  • Exception

Source:

registerServices (services)

Registers new services.

Parameters:
Name Type Description
services object
Throws:
  • Exception

Source:

toString () → {string}

Returns a string representation of the object.

Returns:
  • string
Source: