Updating the Monolith Modules
Explore how to update monolith modules in a Golang application using event sourcing concepts. Learn to modify aggregates with new constructors, replace event name methods with constants, and adjust event handlers for payload type assertions. This lesson helps you ensure your event-driven architecture code compiles and runs correctly after applying key structural updates.
We'll cover the following...
We will be using the Store Management module to demonstrate the code updates that each module will receive. The rest we will leave for you or your compiler to explore on your own.
Updating the aggregates
All of the locations in the monolith modules where new aggregates were instantiated will need to be modified to utilize the new NewAggregate() constructor. This modification is done in a few parts. We will create a constant to contain the aggregate name, create a constructor for the aggregate, and finally, replace each occurrence of aggregate instantiation.
For the Store aggregate, the following constructor is added:
const StoreAggregate = "stores.Store"func NewStore(id string) *Store {return &Store{Aggregate: ddd.NewAggregate(id, StoreAggregate),}}
Then, in CreateStore() ...