问题
I am working with DDD
and Spring
using MongoDB
.
Now the since MongoDB
is a DocumentDB
and no schema validations are present, The AggregateRoot
and the Document class that gets stored in the MongoDB are two different classes and the Repository
translates content between those two classes while reading and writing data to database
.
Since the Root entity class is different from the class being stored to DB, Spring doesn't trigger the DomainEvents
of the AggregateRoot
.
Is there a way I can get trigger the events of the Root entity from the Repository after storing the data to the database? (maybe by an explicit invoke)
Since the MongoDB and Aggregates are a 1:1 fit. So does that mean that we generally shouldn't make a two different classes one as
AggregateRoot
and another the Document Class for storing aggregate roots in mongoDB? Wouldn't we have to add @Document annotation on top of our Aggregate which would leak infrastructure code in our Domain Model?
来源:https://stackoverflow.com/questions/61632788/domain-events-with-spring-boot-and-mongodb