Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Last active Aug 3, 2022
Embed
What would you like to do?
public class PlaceOrderSaga :
Saga<PlaceOrderSagaData>,
IAmStartedByMessages<OrderPlaced>,
IHandleMessages<OrderBilled>,
IHandleMessages<ShippingLabelCreated>
{
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<PlaceOrderSagaData> mapper)
{
mapper.MapSaga(saga => saga.OrderId)
.ToMessage<OrderPlaced>(msg => msg.OrderId)
.ToMessage<OrderBilled>(msg => msg.OrderId)
.ToMessage<ShippingLabelCreated>(msg => msg.OrderId);
}
public async Task Handle(OrderPlaced message, IMessageHandlerContext context)
{
await context.Send(new BillOrder
{
OrderId = message.OrderId
});
}
public async Task Handle(OrderBilled message, IMessageHandlerContext context)
{
await context.Send(new CreateShippingLabel
{
OrderId = message.OrderId
});
}
public async Task Handle(ShippingLabelCreated message, IMessageHandlerContext context)
{
await context.Send(new ReadyToShipOrder
{
OrderId = Data.OrderId
});
MarkAsComplete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment