A simple dependency injection module.
Use the "injectable" decorator to mark your injectable service providers,
then use the "resolve" function to acquire the fully resolved top-level service object.
If your service provider extends AutoInject, then it does not need a constructor -
it can use "Constructor-less Dependency Injection", relying on the AutoInject constructor
to attach its dependencies.
Properties:
Name | Type | Description |
---|---|---|
injectable |
function | The dependency injection decorator function. |
autoinjectable |
function | A base class for managing "constructor-less" injection. |
resolve |
function | The service class resolver function. |
DI |
Object | A DI namespace containing the injectable() and resolve() functions and the AutoInject class. |
Examples
import {injectable} from 'effortless-di';
import {resolve} from 'effortless-di';
@injectable(Service1, ...)
class Application { constructor(service1, ...) { ... }, run() { ... } }
resolve(Application).run();
import DI from 'effortless-di';
@DI.injectable(Service1, ...)
class Application extends DI.AutoInject { run() { ... } }
DI.resolve(Application).run();