async-didi
v1.0.0
Published
Async Dependency Injection for JavaScript
Downloads
81
Maintainers
Readme
async-didi
An async version of didi, the tiny inversion of control container for JavaScript.
Example
import {
AsyncInjector
} from 'async-didi';
function Car(engine) {
this.start = function() {
return engine.start();
};
}
async function createEngine(power) {
return {
async start() {
console.log('Starting engine with ' + power + 'hp');
}
};
}
const injector = new AsyncInjector([
{
'car': ['type', Car],
'engine': ['factory', createEngine],
'power': ['value', 1184]
}
]);
await injector.invoke(async function(car) {
await car.start();
});For more examples, check out the tests.
Usage
Refer to didi documentation and enjoy the ability to define async factory functions and module initializers.
See also comparison.
Comparison to didi
- Same core features
- Exposes an
AsyncInjector - Injector API functions
get,invokeandinstantiateare async - Factory functions may be async
- No support for child injectors and scopes
License
MIT
