Using Event Sourced Aggregate Roots with the Specification Pattern

by designermonkey   Last Updated January 02, 2018 15:05 PM

I have a Aggregate Roots that use the event sourcing technique of being built from a series of events in a Repository. This is all great for when I just need to manage change of state etc, but when I come to using the Specification pattern to apply my app specific business rules, I am hitting a wall on what Entities to use, how to instantiate them etc etc.

I would want to run specific methods on my Repository, for example getProductByProductCode so I can check my current AR against it for uniqueness (simple example), but I am unsure how to do this, as my Repository is set up to get ARs by their ID from the event store.

I used to have a database backing my Repositories, now I only have an event store as I have no read models yet.

  • Has anyone done this before, and how did you do it?
  • Do I need a read model first?
  • Should I query the read model, then use a resulting ID to get the AR from the event store?
  • What if I need multiple AR results to be returned?

I am so confused as I thought I was doing it all the right way now as we need event sourcing, but I can't seem to marry up my old-school thinking with how to do it now it's event sourced :(

Related Questions

CQRS - Passing aggregate root as argument

Updated February 25, 2017 23:05 PM

Event sourcing - applying events before change is done?

Updated December 23, 2016 08:02 AM