In a C# solution I'm working at, the core of application logic is implemented as a state-machine by means of (very good) Stateless library. There are other parts of business logic modeled in a number of other classes, for the different areas and features the app shows, but this is the one driving the main changes in underlying app states.
Although every state transition is quite simple in itself (notifying events, setting eventArgs, listening to other events, ...) and I'm using substates when applicable, to me it's starting to look like somehow too big. I understand this is not an exact measure, but if you look and think about substates, you may well end up finding that they could be distinct state machines on their own.
Is there an evident way that I'm missing to build separate sub-statemachine (so to say) with Stateless, mapping every state machine to a distinct class (and file)?
The first blocking issues that come to my mind are (especially the second):
the one-big-piece state machine triggers events on all state changes: after the split, each single state machine would fire each own triggers. So there would better be a façade collecting all events and re-triggering them for the clients, so to hide the many state machines (after all they are an implementation detail for clients).
Stateless substates take care of bubbling triggers up the state/substate chain, as well as downwards. So e.g. for a given state
A
having substates, one can define a trigger (in one place,A
's Configure) that will make the state machine leaveA
, no matter in which substate ofA
we will be. How does this work with separate sub-state machines?