Skip to content

Instantly share code, notes, and snippets.

@jasonyandell
Created March 16, 2012 17:07
Show Gist options
  • Save jasonyandell/2051176 to your computer and use it in GitHub Desktop.
Save jasonyandell/2051176 to your computer and use it in GitHub Desktop.
Saga state machine definition (Chris Patterson)
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