Skip to content

Instantly share code, notes, and snippets.

@jasonyandell
Created March 16, 2012 17:06
Show Gist options
  • Save jasonyandell/2051167 to your computer and use it in GitHub Desktop.
Save jasonyandell/2051167 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());
});
}
// event and state definitions not shown, but are simple properties
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment