247
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
// Other configuration
var
navigation =
orderConfiguration.
Metadata
.
FindNavigation
(
nameof
(Order.
OrderItems
));
//EF access the OrderItem collection property through its backing field
navigation.
SetPropertyAccessMode
(PropertyAccessMode.
Field
);
// Other configuration
}
}
When you use fields
instead of properties, the
OrderItem
entity is
persisted as if it had a
List
property. However, it exposes a single accessor, the
AddOrderItem
method, for
adding new items to the order. As a result, behavior and data are tied together and will be consistent
throughout any application code that uses the domain model.
Implement custom repositories with Entity Framework Core
At the implementation level, a repository is simply a class with data persistence code coordinated by a
unit of work (DBContext in EF Core) when performing updates, as shown in the following class:
// using directives...
namespace
Microsoft.
eShopOnContainers
.
Services
.
Ordering
.
Infrastructure
.
Repositories
{
Dostları ilə paylaş: