Lab 4 - TDD Aggregate Repository - Rehydrate Kitchen Aggregates by Reference
1. Summary
When using Event Sourcing without CQRS, the only way to find an Aggregate is to "rehydrate" it from the list of events that it has published. This find operation can only be indexed by primary key.
In this lab, we’ll implement find by reference for the Kitchen context Aggregates.
We will complete two stories:
-
We will support finding a
KitchenOrderby itsKitchenOrderRef. -
We will support finding a
Pizzaby itsPizzaRef.
You can run com.mattstine.dddworkshop.pizzashop.suites.Lab4Suite to check your progress in this lab.
2. Instructions
-
Our generic
InProcessEventSourcedRepositoryimplementation depends primarily on two methods that must exist on eachAggregate:-
identity -
accumulatorFunction
-
-
The implementations of both of these methods on
KitchenOrderandPizzaare broken. You have to fix them. -
Implementing
identityis fairly straightforward. Use the builder for the Aggregate to construct a new instance, setting each property to itsIDENTITYvalue, and return it. -
The implementation of
accumulatorFunctionis fine, but you’ll need to fix theAccumulatorobject it returns by implementing itsapplymethod. -
To properly implement
apply, you need to check the type of theAggregateEventpassed as an argument, and for each event type published for thatAggregate, perform the appropriate state transformation. -
If you’re looking for hints, try looking at the
applyimplementations in the Ordering and Payments contexts.