Dependency injection

If your service uses a dependency injection provider and you want to use it to resolve class based handlers and workflows, you can provide an adapter to @node-ts/bus-core for it to use.
This is provided as an adapter passed using .withContainer() to the configuration.
This example uses inversify, but any IoC container that supports resolving instances via a class type will work.
import { Bus, ClassConstructor } from '@node-ts/bus-core'
import { Container } from 'inversify'
​
const start = async () => {
const container = new Container()
​
const bus = await Bus.configure()
.withContainer({
get <T>(type: ClassConstructor<T>) {
return container.get<T>(type)
}
})
.initialize()
}