Chapter specific transition within a saga

34 views
Skip to first unread message

Pavneet Singh Saund

unread,
May 24, 2012, 8:08:44 AM5/24/12
to bifrost...@googlegroups.com
When transitioning between chapters in a saga, there's a concept of ChapterValidation. Given a successful validation, the transitions completes, otherwise it fails: 

public SomeChapter : Chapter, ICanTranstionTo<AnotherChapter> {...}
public class SomeChapterValidator : ChapterValidator<SomeChapter> {...}
 
sagaNarrator.TransitionTo<AnotherChapter>(saga); //success or fail based on SomeChapterValidator


This falls through a bit, when implementing flow between chapters, where different validation applies to different transitions. In the following example, if SecondChapter isn't valid, it cant transition back to FirstChapter
Example:

public SecondChapter : Chapter, ICanTranstionTo<FirstChapter>, ICanTransitionTo<LastChapter> {...}
public class SecondChapterValidator : ChapterValidator<SecondChapter> {...} 

sagaNarrator.TransitionTo<FirstChapter>(saga); //fails, even though we might not want validation when going back to first step

Given that Chapters build up a state machine, it leads me to believe that transitions should be able to validate differently. Meaning that different transitions should have it's own validators. Or rather be specific when a specific transition needs validation. Something on the lines of:

public class SecondChapterValidator : ChapterValidatorBetween<SecondChapter,LastChapter> {...}  //complex rules
public class SecondChapterValidator : ChapterValidatorBetween<SecondChapter,FirstChapter> {...}  //no rules, or just non existent

Given CurrentChapter is SecondChapter:
sagaNarrator.TransitionTo<LastChapter>(saga); // fails if is unvalid
sagaNarrator.TransitionTo<FirstChapter>(saga); // fails if is unvalid 
 
 
Thoughts?

Pavneet Singh Saund

unread,
May 24, 2012, 8:12:29 AM5/24/12
to bifrost...@googlegroups.com
Ignore the obvious syntax typos :)

Pavneet Singh Saund

unread,
May 24, 2012, 8:20:04 AM5/24/12
to bifrost...@googlegroups.com
Alternatively, there could be something that requires you to specify if validation is desired between transitions. Or maybe even build in a state-machine flow, where moving back doesn't require validation, but this does seem a little naive in the long run

Michael Smith

unread,
May 24, 2012, 9:33:26 AM5/24/12
to bifrost...@googlegroups.com
We've already run into problems with ChapterValidation.  The ChapterValidation validates that the chapter you are transitioning from is in a valid state (which is reasonable enough) but not that the chapter you are transitioning to has it's pre-requisites taken care of.  If I remember right, it was we needed the Payment Credentials in the PlaceOrderChapter as we would perform the reservation in the OnTransitionedTo event.  I think I ended up letting the absence of credentials mean that the attempt to perform the reservation would throw an exception and the transition would therefore fail.

The transitioning / validation is too simplistic.  We shouldn't be validating the chapter, we should validate the transition between two chapters (a from and a to).  Though we've also spoken about making the Saga itself a proper state machine in which case it would handle state transitions internally, rather than rely on something external to say "try and transition to the next chapter".

Pavneet Singh Saund

unread,
May 24, 2012, 5:07:37 PM5/24/12
to bifrost...@googlegroups.com
Saga as a statemachine, handling transistions makes sense. The ChapterTransitionValidator is still going to have to play a part in that logic as well, methinks.
I think I'll go ahead and make an issue on GH for this, and we can continue things there.
Reply all
Reply to author
Forward
0 new messages