Projections with State
In order to optimize projections or to avoid using external storage, we may use of
Projection's State. State is data that is kept between executions and can be passed to Projection's Event Handler.
In order to pass the state to Projection's Event Handlers we need to mark method parameter with
final class TicketCounterProjection
const NAME = "ticket_counter";
public function when(TicketWasRegistered $event, #[ProjectionState] TicketCounterState $state, EventStreamEmitter $eventStreamEmitter): TicketCounterState
$state = $state->increase();
Ecotone will resolve this parameter and pass the state. The returned state from the Event Handler will becomes new state for next execution. We may pass the state between all Event Handlers in given Projection.
You may want to fetch the state from outside to return it to the end user. In that case Ecotone brings
public function getCounter(): TicketCounterState;