I'm doing a project in PHP and I'm implementing Aggregates and Event Sourcing. In order to avoid coding up all the logic related with ES myself I've decided to use a third party library called EventSauce.
I would want to avoid coupling my code, specially my domain, with an external library. However, from what I have seen in the docs I need to use classes that implement the EventSauce interfaces. I would like to use my own interfaces in order to have control of the possible changes made to the library or if I would like to change to another library in the future. I would illustrate this with an example.
I have a repository with the following interface:
interface ItemRepository
{
public function itemOfSku(Sku $sku): Item;
public function nextSku(): Sku;
public function save(Item $item): void;
}
And the library needs an interface, which is kind of equivalent, like:
interface MessageRepository
{
public function persist(Message ... $messages);
public function retrieveAll(AggregateRootId $id): Generator;
}
Other parts of the library depend on this MessageRepository
so I am forced to implement this interface. If this restriction doesn't exist it would be much easier.
I would like to know if there is any design pattern that would allow me to decople from the third party interface and not pollute my domain.
The implementation of the repository is not part of the domain but the interface of the repository can be
Are you perhaps implementing the port-&-adapter architecture? Because basically that's a way to decouple your domain from the "implementation details" imposed by the framework.