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

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_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) → {*}

Inject a static class with the services it requests. This mutates the class' prototype.

Parameters:
Name Type Description
Class
Returns:
  • the injected static reference to the Class
Type
*

service(service) → {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
service string

the name of the service

Returns:
  • the service instance or service container proxy
Type
module:flitter-di/src/Service~Service | undefined | Proxy