Package dk.cloudcreate.essentials.components.eventsourced.aggregates.stateful.modern
-
Interface Summary Interface Description WithState<ID,EVENT_TYPE,AGGREGATE_TYPE extends AggregateRoot<ID,EVENT_TYPE,AGGREGATE_TYPE>,AGGREGATE_STATE extends AggregateState<ID,EVENT_TYPE,AGGREGATE_TYPE>> Marker interface that indicates that all state and allEventHandlerannotated methods will be hosted with theAggregateStateobject. -
Class Summary Class Description AggregateRoot<ID,EVENT_TYPE,AGGREGATE_TYPE extends AggregateRoot<ID,EVENT_TYPE,AGGREGATE_TYPE>> A modern opinionated interpretation of the classicAggregateRootdesign, where theEvent's are mutable.
The modern interpretation doesn't specify any requirement on the design of the Events, they can be Java 17+ records or simple POJO's.
Note: TheAggregateRootworks best in combination with theStatefulAggregateRepositorythat's configured to use theStatefulAggregateInstanceFactory.reflectionBasedAggregateRootFactory(), because theAggregateRootneeds to be provided its aggregated id through theAggregateRoot(Object)constructor!
The modernAggregateRootsupports keeping the state projection andEventHandlerannotated methods within theAggregateRootinstance or within anAggregateStateinstance.
If you wish to keep the state projection andEventHandlerannotated methods within anAggregateStateinstance, then you only need to implement theWithStateinterface:AggregateState<ID,EVENT_TYPE,AGGREGATE_TYPE extends AggregateRoot<ID,EVENT_TYPE,AGGREGATE_TYPE>> Aggregate state object associated with a givenAggregateRootinstance (seeAggregateState.getAggregate())
Example: