Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 697 Bytes

File metadata and controls

24 lines (18 loc) · 697 Bytes

Access Event Store

Use Event Store directly

In some cases you may want to access Event Store directly.
Event Store is auto registered in your Dependency Container, so you can fetch it like any other service or inject it directly to any Handler.

use Ecotone\EventSourcing\EventStore;
    
    #[QueryHandler(self::GET_CURRENT_BALANCE_QUERY)]
    public function getCurrentBalance(#[Reference] EventStore $eventStore): array
    {
        $streamName = "wallet";
        if (!$eventStore->hasStream($streamName)) {
            return [];
        }

        /** @var Event[] $event */
        $events = $eventStore->load($streamName, count: 10);

        return $events;
    }