Raise event inside Activity and Observer

354 views
Skip to first unread message

Alex Michel

unread,
Oct 14, 2015, 3:54:14 PM10/14/15
to masstransit-discuss
Hi,
Is it fine to raise state machine events inside activity that is called in Execute method?
In this case it is pure Automatonymous state machine - not saga.
E.g. if I create delegates that wrap event lifters and pass it in constructor, so that activity will end up raising one of the events (completed or failed)? 
Wouldn't that cause cyclic dependency? 

Another scenario I have is parent and child state machines, where parent is observer of child fsm,
and on certain transition of child it would raise event with lifter to move itself to the next state.

Thanks

Chris Patterson

unread,
Oct 15, 2015, 12:16:58 PM10/15/15
to masstrans...@googlegroups.com
Well, you should be able to raise events from within event activities, I'm not sure how dangerous that is because you could end up in a bad place. If you raise the event, however, you'd need to make sure any state transitions have taken place in advance of raising the event. Injecting lifts is a good approach to avoid coupling directly to the state machine, I would agree.

Also, using an "activity factory" to create the activities (we resolve them from a container) instead of creating the activities in the state machine itself can help keep things decoupled.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/718558ba-7aa1-4471-a0f1-2e4f9e003e29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Michel

unread,
Oct 21, 2015, 7:56:39 AM10/21/15
to masstransit-discuss
Hi Chris,
It seems to work with regular state machine, 
but when I do it inside Saga it always fails with "The consume context could not be retrieved."  'MassTransit.ContextException' in MassTransit.AutomatonymousIntegration.dll
I tried to simply call RaiseEvent inside Then.





Reply all
Reply to author
Forward
0 new messages