DependencyInject
Live Demo
import { Container, inject } from 'dependency-inject'
class Store {
num = 1
}
class Action {
@inject(Store)
private store: Store
setNum(num: number) {
this.store.num = num
}
}
const container = new Container()
container.set(Store, new Store())
container.set(Action, new Action())
const store = container.get(Store)
const action = container.get(Action)
action.setNum(2)
console.log(store.num)
Simple useage by injectFactory
import { injectFactory } from 'dependency-inject'
class Store {
num = 1
}
class Action {
@inject(Store)
private store: Store
setNum(num: number) {
this.store.num = num
}
}
const stores = injectFactory({Store, Action})
nested object
import { injectFactory } from 'dependency-inject'
class Store {
num = 1
}
class Action {
@inject(Store)
private store: Store
setNum(num: number) {
this.store.num = num
}
}
const stores = injectFactory({
groupA: Store,
groupB: {
groupC: Action
}
})