...

/

Adding the Event Sourcing Package

Adding the Event Sourcing Package

Implement the event-sourced aggregates by embedding existing aggregates to support event sourcing in our application.

The updates made to enhance the events did not add any new code to support event sourcing. Because we do not want to turn every aggregate in the application into an event-sourced aggregate, the bits necessary to support event sourcing will go into a new internal/es package.

Creating the event-sourced aggregate

To avoid having to build the aggregate from scratch, this new aggregate will contain an embedded ddd.Aggregate and provide a new constructor. Here is what we are starting with, the event-sourced Aggregate definition:

Press + to interact
The event-sourced Aggregate
The event-sourced Aggregate

Adding a constructor

This new Aggregate will also need a constructor:

func NewAggregate(id, name string) Aggregate {
return Aggregate{
Aggregate: ddd.NewAggregate(id, name),
version: 0,
}
}
The new aggregate with constructor

Adding the es.Aggregate struct

The purpose of es.Aggregate struct is to layer on the versioning controls required to work with the event-sourced aggregates. It accomplishes this by embedding ddd.Aggregate. The ...