Skip to content

Facades

We offer facades for easy access to event sourcing services. You can use the facades to access the repositories, the store or manage your aggregates. This feature is optional, you can still use the services directly via dependency injection.

Aggregate

If your aggregates extend the laravel package provided AggregateRoot class, you can use the helper methods to load and save your aggregates.

use Patchlevel\EventSourcing\Attribute\Aggregate;
use Patchlevel\LaravelEventSourcing\AggregateRoot;

#[Aggregate(name: 'hotel')]
final class Hotel extends AggregateRoot
{
    // ...
}
With the static load method of your specific aggregate class you can load your aggregates.

use Patchlevel\EventSourcing\Aggregate\Uuid;

$hotel = Hotel::load(Uuid::fromString('123'));
And save them by using the save method on the aggregate instance.

$hotel->save();

Repository

You can access the specific repositories using the get method of the Repository facade.

use Patchlevel\LaravelEventSourcing\Facade\Repository;

$repository = Repository::get(Hotel::class);

Store

You can access the store using the Store facade. There you can save multiple messages at once:

use Patchlevel\LaravelEventSourcing\Facade\Store;

Store::save(/* messages... */);
or load messages by criteria:

use Patchlevel\EventSourcing\Store\Criteria\AggregateIdCriterion;
use Patchlevel\EventSourcing\Store\Criteria\Criteria;
use Patchlevel\LaravelEventSourcing\Facade\Store;

$messages = Store::load(
    new Criteria(
        new AggregateIdCriterion('123'),
    ),
);

Note

This documentation is limited to the package integration. You should also read the library documentation.

Projection Connection

You can access the projection connection using the ProjectionConnection facade. This facade provides you the DBAL\Connection used to connect to the projection database.

Note

This documentation is limited to the package integration. You should also read the dbal documentation.

CommandBus

You can access the command bus using the CommandBus facade. With this facade you can dispatch commands.

CommandBus::dispatch(new BookHotel());
Then, the command will be handled by the corresponding command handler specified via #[Handle] attribute.

QueryBus

You can access the query bus using the QueryBus facade. With this facade you can dispatch queries.

$result = QueryBus::dispatch(new HotelCountQuery());
Then, the query will be handled by the corresponding query handler specified via #[Answer] attribute.