// This is a little bit cute, but the HappyMealOrderState type // is known to be the saga state document, so it'll be treated as // the state document, while the object[] will be treated as // cascading messages public (HappyMealOrderState, object[]) Starts(HappyMealOrder order) { var state = new HappyMealOrderState { Order = order, Id = ++_orderIdSequence }; return(state, chooseActions(order, state.Id).ToArray()); }
private IEnumerable <object> chooseActions(HappyMealOrder order, int stateId) { // choose the outgoing messages to other systems -- or the local // system tracking all this -- to start having this happy meal // order put together if (order.Drink == "Soda") { yield return(new SodaRequested { OrderId = stateId }); } // and others }
// This is a little bit cute, but the HappyMealOrderState type // is known to be the saga state document, so it'll be treated as // the state document, while the object[] will be treated as // cascading messages public async Task <HappyMealOrderState> Starts(HappyMealOrder order, IMessageContext context) { var state = new HappyMealOrderState { Order = order, Id = ++_orderIdSequence }; // You can explicitly call the IMessageContext if you prefer if (order.Drink == "Soda") { await context.Send(new SodaRequested { OrderId = state.Id }); } return(state); }
// SAMPLE: HappyMealSaga1Local public async Task <HappyMealOrderState> Starts( HappyMealOrder order, // The first argument is assumed to be the message type IMessageContext context) // Additional arguments are assumed to be services { var state = new HappyMealOrderState { Order = order, Id = ++_orderIdSequence }; if (order.Drink == "Soda") { await context.Enqueue(new SodaRequested { OrderId = state.Id }); } // And other outgoing messages to coordinate gathering up the happy meal return(state); }