I have 4 entity types, each has its own StateMachine. There are transitions which also should invoke transitions on one or more different entity types.
I can solve this via the event system (either in entered
or transition
events) but this just doesn't look right. And it's hard to follow all cases and ensure that all dependencies are taken care of.
What would be a design-pattern for such a use-case? I need a way to connect independent StateMachines together.
As much as I appreciated @StepUp's answer, it doesn't quite fit my needs. The Applicaiton already uses events quite a bit (or read messages). CQRS would be a major rewrite and as the auditing of the state changes is not needed I don't see a big enough benefit in it. Saga seems interesting but as this is not a microservice context is would be to much.
After thinking about it for quite some time I come to the realisation that Observer would just inverse the responsibility to the other side. I need something central.
The solution will be a Mediator Pattern. The Mediator (and only the mediator) will know about which workflow has dependencies on other workflows. The Workflow itself doesn't need to know this. As the StateMachine already fires events, I can use them to call the mediator and the Mediators will know what to do.