0

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)
Proggear
  • 662
  • 6
  • 10

1 Answers1

1

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.

Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
  • Separate handler for FirstCompletedEvent is not enough. For now I store data in state and trigger one more FirstCompletedInternalEvent. It works, however I hope there is some less complicated solution. – Proggear Oct 07 '22 at 13:10
  • Updated to explain how the ordering matters. – Chris Patterson Oct 07 '22 at 14:26