Thursday, February 25, 2016

Inheritance with Aggregate Roots in ProophEvent-Store

If you want to make inheritance work with aggregate roots using a common repository for all subtypes, this can be achieved very easily. You need the latest ProophEvent-Store v6.1 to do this.

An example


Consider the following use case:

So in order to make this work, you need 3 small changes in your application.

Step 1: Create a UserAggregateTranslator



Step 2: Change the assertion method in the EventStoreUserCollection



Step 3: Make use of your custom AggregateTranslator



If you use the provided container factory (\Prooph\EventStore\Container\Aggregate\AbstractAggregateRepositoryFactory) then you can also just change the aggregate_translator key in your config to point to the new UserAggregateTranslator and register the UserAggregateTranslator in your container.

No comments:

Post a Comment