Created
March 16, 2012 17:07
-
-
Save jasonyandell/2051176 to your computer and use it in GitHub Desktop.
Saga state machine definition (Chris Patterson)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrinkPreprationStateMachine : | |
StateMachine < DrinkPreprationStateMachine >, | |
ISaga, | |
InitiatedBy < NewOrderMessage >, | |
Orchestrates < PaymentCompleteMessage >, | |
Orchestrates < DrinkPreparedMessage > | |
{ | |
static DrinkPreprationStateMachine() | |
{ | |
Define(() => { | |
Initially( | |
When(NewOrder) | |
.Then(saga => | |
{ | |
// start preparing the drink | |
}) | |
.TransitionTo(PreparingDrink)); | |
During(PreparingDrink, | |
When(DrinkPrepared) | |
.TransitionTo(WaitingForPayment), | |
When(PaymentComplete) | |
.TransitionTo(WaitingForDrink)); | |
During(WaitingForPayment, | |
When(PaymentComplete) | |
.Then(saga => | |
{ | |
// publish drink ready message | |
}) | |
.Complete()); | |
During(WaitingForDrink, | |
When(DrinkPrepared) | |
.Then(saga => | |
{ | |
// publish drink ready message | |
}) | |
.Complete()); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment