259
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
Id =
20240011
,
ProductId =
"123456"
,
ProductName =
".NET T-Shirt"
,
UnitPrice =
25
,
Units =
2
,
Discount =
0
;
};
//Using methods with domain logic within the entity. No anemic-domain model
orderAggregate.
AddOrderItem
(orderItem1);
// *** End of Domain Model Code ***
// *** Infrastructure Code using Cosmos DB Client API ***
Uri collectionUri = UriFactory.
CreateDocumentCollectionUri
(databaseName,
collectionName);
await client.
CreateDocumentAsync
(collectionUri, orderAggregate);
// As your app evolves, let's say your object has a new schema. You can insert
// OrderV2 objects without any changes to the database tier.
Order2 newOrder =
GetOrderV2Sample
(
"IdForSalesOrder2"
);
await client.
CreateDocumentAsync
(collectionUri, newOrder);
You can see that the way you work with your domain model can be similar to the way you use it in
your domain model layer when the infrastructure is EF. You still use the same aggregate root methods
to ensure consistency, invariants, and validations within the aggregate.
However, when you persist your model into the NoSQL database, the code and API change
dramatically compared to EF Core code or any other code related to relational databases.
Dostları ilə paylaş: