Bootstrapping EventSauce

Last updated at 23 March 2018 | Published at 05 March 2018

Now that you’ve got your MessageRepository and MessageDispatcher in place you’re ready to bootstrap your AggregateRootRepository.

The AggregateRootRepository is the main interface of EventSauce. It’s where you get your aggregate root from and where you persist (persist recorded events) it. When you’re retrieving an aggregate root from the repository it’s responsible for fetching the associated events from the MessageRepository and using that to create an aggregate root. This process is commonly referred to as reconstituting an aggregate root.

The default implementation shipped in EventSauce is the ConstructingAggregateRootRepository. This repository is a sane default implementation and also serves as a reference implementation for if/when you want to create your own implementation.

<?php

use EventSauce\EventSourcing\ConstructingAggregateRootRepository;

$aggregateRootRepository = new ConstructingAggregateRootRepository(
    YourAggregateRootClass::class,
    $messageRepository,
    $messageDispatcher
);

Now you’re ready to start modelling! For more information about how you do this, read the lifecycle documentation.