You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the example workflow in the guide. A normal thing would be to have a workflow requiring a BusInstance:
export class FulfilmentWorkflow extends Workflow<FulfilmentWorkflowState> {
constructor (bus: BusInstance) {}
In order to setup dependency injection the examples show:
const container = new Container()
const bus = await Bus.configure()
.withContainer({
get <T>(type: ClassConstructor<T>) {
return container.get<T>(type)
}
})
.initialize()
Now I 'would' have i BusInstance and can add it to the DI container.
The problem is, that initialize tries to create all workflows using the DI container.
So it will try to construct FulfulmentWorkflow, and to do that, the DI container will try to get the BusInstance, but this is not added yet.
And cannot be added, because we still don't have the bus instance...
So as I can see it, we are in a vicious circle :)
We are updating from 1.0.0. This seems to be added with
Use container to get workflows: #169
Am I completely missing something? (wouldn't be the first time)
The text was updated successfully, but these errors were encountered:
hi @mathiasbn - what you're running into is not uncommon. The .initialize() step requests instances of each workflow from your DI container in order to determine what messages are consumed so it can configure queues and subscriptions. During this step, your workflow is never run - just the configureWorkflow function is executed.
One way to ensure that the BusInstance is available when a message eventually activates your workflow is to dynamically/late bind it. I've provided an example at https://github.com/node-ts/examples/blob/basic-example/src/basic-workflow/index.ts#L21 that uses an Inversify container, but any reasonable mature DI provider should give you the same ability.
Hi again. Thank you for responding, and I'm sorry I totally forgot to answer.
That helped me on, I still find it a little tricky, but there is probably a good reason.
Anyways this can be closed
From the example workflow in the guide. A normal thing would be to have a workflow requiring a BusInstance:
In order to setup dependency injection the examples show:
Now I 'would' have i
BusInstance
and can add it to the DI container.The problem is, that
initialize
tries to create all workflows using the DI container.So it will try to construct FulfulmentWorkflow, and to do that, the DI container will try to get the BusInstance, but this is not added yet.
And cannot be added, because we still don't have the bus instance...
So as I can see it, we are in a vicious circle :)
We are updating from 1.0.0. This seems to be added with
Use container to get workflows: #169
Am I completely missing something? (wouldn't be the first time)
The text was updated successfully, but these errors were encountered: