DependencyInjector

flitter-di/src/DependencyInjector~ DependencyInjector

Manages services and injects classes from its service container.


Constructor

new DependencyInjector()

Members

container :module:flitter-di/src/Container~Container

The service container used by this dependency injector.

Methods

(private) __is_injectable(Class) → {boolean}

Verify that a class is injectable. This means that it has a static __inject method and that method takes at least one argument. In almost all cases, this should be satisfied by using the Injectable base class.

Parameters:
Name Type Description
Class *

the class to check

Returns:
  • true if the class is injectable
Type
boolean

get(name) → {*}

Fetch an IoC item by name.

Parameters:
Name Type Description
name string
Returns:
Type
*

has(name) → {boolean}

Verify that the injector's container has a service or set of services.

Parameters:
Name Type Description
name string | Array.<string>

service name or array of service names

Returns:
  • true if the container has the service(s)
Type
boolean

inject(Class) → {*}

Inject the passed in Class with the IoC items it requires.

Parameters:
Name Type Description
Class
Returns:
Type
*

inject_globally()

If called, this method will extend the global nodejs require() method to check for injectable classes. If a require value is injectable, it will be automatically injected with the services from this DI.

make(Class, …args) → {*}

Instantiate the passed in class. If it is injectable, it will be injected.

Parameters:
Name Type Attributes Description
Class
args * <repeatable>

additional arguments to be passed to the constructor of the class

Returns:
  • the injected static reference to the Class
Type
*

service(name) → {module:flitter-di/src/Service~Service|undefined|Proxy}

Fetch a service by name. If no name is provided, return the service proxy container. This container has getters for all the services by name.

Parameters:
Name Type Description
name string

the name of the service

Deprecated:
  • - prefer DependencyInjector.get. This will be removed in the future.
Returns:
  • the service instance or service container proxy
Type
module:flitter-di/src/Service~Service | undefined | Proxy