async-didi
An async version of didi, the dependency injection library for JavaScript.
Example
function Car(engine) {
this.start = function() {
engine.start();
};
}
const createEngine = async function(power) {
return {
start: function() {
console.log('Starting engine with ' + power + 'hp');
}
};
};
const {
AsyncInjector
} = require('async-didi');
var injector = new AsyncInjector([
{
'car': ['type', Car],
'engine': ['factory', createEngine],
'power': ['value', 1184]
}
]);
await injector.invoke(function(car) {
car.start();
});
For more examples, check out the tests.
Usage
Checkout didi for detailed usage instructions.
Differences to didi
- async
get
, invoke
and instantiate
methods - support for async factory functions
- no support for child injectors and scopes