I've got some events in state machine
public Event<FirstCompletedEvent>? FirstCompletedEvent { get; set; }
public record FirstCompletedEvent(Guid PaymentKey, string PaymentDetails) : IQueueMessage;
public Event<SecondCompletedEvent>? SecondCompletedEvent { get; set; }
public Event<ThirdCompletedEvent>? ThirdCompletedEvent { get; set; }
AllCompletedEvent
fires when all of 3 arrived.
CompositeEvent(() => AllCompletedEvent, x => x.AllCompletedEventStatus,
FirstCompletedEvent,
SecondCompletedEvent,
ThirdCompletedEvent);
Question: is it possible to pass data from FirstCompletedEvent
into AllCompletedEvent
for futher processing. To make something like this:
During(Payout,
When(AllCompletedEvent)
.Then(c => DoSomething(c.Data.PaymentDetails)
I've tried to save it to state in event handler, but it fired (if fired at all) after When(AllCompletedEvent
) - absolutely not what I looking for.
When(FirstCompletedEvent)
.Then(c => c.Instance.PaymentDetails = c.Data.PaymentDetails)
Any event data required in subsequent events should be stored in the state instance by that event's specific event handler. A composite event only stores the fact that the event was raised, not the data included in it.
UPDATE
Also, you need to define the CompositeEvent
after:
When(FirstCompletedEvent)
.Then(c => c.Instance.PaymentDetails = c.Data.PaymentDetails)
So that the composite event fires after the FirstCompletedEvent
.