241
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
memory with the data passed with the commands, and you then add or update the data (domain
entities) in the database through a transaction.
It’s important to emphasize again that you should only define one repository for each aggregate root,
as shown in Figure 7-17. To achieve the goal of the aggregate root to maintain transactional
consistency between all the objects within the aggregate, you should never create a repository for
each table in the database.
Figure 7-17. The relationship between repositories, aggregates, and database tables
The above diagram shows the relationships between Domain and Infrastructure layers: Buyer
Aggregate depends on the IBuyerRepository and Order Aggregate depends on the IOrderRepository
interfaces, these interfaces are implemented in the Infrastructure layer by the corresponding
repositories that depend on UnitOfWork, also implemented there, that accesses the tables in the Data
tier.
Dostları ilə paylaş: