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.
1
import { Bus, ClassConstructor } from '@node-ts/bus-core'
2
import { Container } from 'inversify'
3
​
4
const start = async () => {
5
const container = new Container()
6
​
7
const bus = await Bus.configure()
8
.withContainer({
9
get <T>(type: ClassConstructor<T>) {
10
return container.get<T>(type)
11
}
12
})
13
.initialize()
14
}
Copied!
Copy link