Experiments around DI and IoC
DI/IoC is nice and useful idea. There're several good JS implementations of this concept:
- Inversify
- Awilix and Jeff's great article
... - di-decorators by Luis Gustavo Vilela de Oliveira
- js-ioc-container by Andreas Kihlberg
But nothing is perfect.
So we need yet another one DI container absolutely incompatible with others.
import {Container, CLASS} from 'di-container'
class Bar {
baz() {return 'qux'}
}
class Foo {
constructor (bar) {
this.bar = bar
}
}
const container = new Container()
container.register(Bar, {type: CLASS})
container.register(Foo, {deps: [Bar], type: CLASS})
const foo = container.get(Foo)
const qux = foo.bar.baz();
- Scopes
- Proxies
- Aliases
- Lazy consistency check
- Decorators