https://github.com/nikku/async-didi
The async fellow of didi - dependency Injection for JavaScript
https://github.com/nikku/async-didi
dependency-injection didi ioc javascript nodejs
Last synced: about 1 month ago
JSON representation
The async fellow of didi - dependency Injection for JavaScript
- Host: GitHub
- URL: https://github.com/nikku/async-didi
- Owner: nikku
- License: mit
- Created: 2019-07-19T22:53:08.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2025-12-16T18:27:59.000Z (6 months ago)
- Last Synced: 2025-12-20T08:56:43.991Z (6 months ago)
- Topics: dependency-injection, didi, ioc, javascript, nodejs
- Language: JavaScript
- Homepage:
- Size: 362 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# `async-didi`
[](https://github.com/nikku/async-didi/actions?query=workflow%3ACI)
An async version of [`didi`][didi], the tiny [inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control) container for JavaScript.
## Example
```js
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](https://github.com/nikku/async-didi/blob/main/test/async-injector.spec.js).
## Usage
Refer to [`didi` documentation](https://github.com/nikku/didi?tab=readme-ov-file#usage) and enjoy the ability to define `async` factory functions and module initializers.
See also [comparison](#comparison-to-didi).
## Comparison to [`didi`][didi]
* Same core features
* Exposes an `AsyncInjector`
* Injector API functions `get`, `invoke` and `instantiate` are async
* Factory functions may be async
* No support for child injectors and scopes
## License
MIT
[didi]: https://github.com/nikku/didi