206
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
Figure 7-11. The order aggregate in Visual Studio solution
If you open any of the files in an aggregate folder, you can see how it is
marked as either a custom
base class or interface, like entity or value object,
as implemented in the
SeedWork
folder.
Implement domain entities as POCO classes
You implement a domain model in .NET by creating POCO classes
that implement your domain
entities. In the following example, the Order class is defined as an entity
and also as an aggregate
root. Because the Order class derives from the Entity base class, it can reuse common code related to
entities. Bear in mind that these base classes and interfaces are defined by you in
the domain model
project, so it is your code, not infrastructure code from an ORM like EF.
// COMPATIBLE WITH ENTITY FRAMEWORK CORE 5.0
// Entity is a custom base class with the ID
public
class
Order : Entity, IAggregateRoot
{
private
DateTime _orderDate;
public
Address Address {
get
;
private
set
; }
private
int
? _buyerId;
Dostları ilə paylaş: