@tractor/dependency-injection
v1.9.4-tractor-to-playwright.0
Published
DI container for tractor
Downloads
68
Keywords
Readme
@tractor/dependency-injection
Dependency Injection container for tractor.
API
constant
Adds a constant reference to the container by name.
Usage
import { DI } from '@tractor/dependency-injection';
DI.constant({ config: { my: 'config' }});
factory
Adds a factory function to the container by name.
Usage
import { DI } from '@tractor/dependency-injection';
DI.factory(function myFunction () {});
call
calls a function with injected dependencies.
Usage
import { DI } from '@tractor/dependency-injection';
let config = {};
DI.constant({ config });
function init (config) {}
init['@Inject'] = ['config'];
DI.call(init);
instantiate
Creates a new instance of a factory with injected dependencies.
Usage
import { DI } from '@tractor/dependency-injection';
let config = {};
DI.constant({ config });
function Engine () {}
DI.factory(Engine);
function Tractor (config, engine) {
this.config = config;
this.engine = engine;
}
Tractor['@Inject'] = ['config', 'Engine'];
DI.factory(Tractor);
let tractor = DI.instantiate(Tractor);