3

I have stumbled through StackOverflow and Google and other sites but could not grasp the concept of how to implement it.

Here I have a very very simple model: An Item and an ItemActivity. It is clear that the Item is the aggregate root and the ItemActivity is an entity.

So according to DDD principles I should only implement ItemRepository. Besides its own -lets say- CRUD operations the ItemRepository should also manage its child entity's, ItemActivity's, CRUD operations too.

And here comes some implementation issues:

  1. Should I implement child entity operations in the domain or repository.
  2. Loading all child entities related to an item or navigating to them is OK with Entity Framework. Loading the root with .include(..) will do the work. But what about updading an ItemActivity or even deleting an ItemActivity? Removing them from the collection does not persist.
  3. Assume that I have to find all activities within a time span. How can such a query be implemented while I cannot query over ItemActivity or worse there does not exist any ItemActivityRepository at all.
  4. Is there a sample covering this topic. There are a lot of articles written about it, many answers without concrete code and theoretical coverages but please, are there any real samples. I have worked on Microsoft Spain N-Layered DDD Sample but it is not detailed enough.

Best regards.

4

1 回答 1

3

1.我应该在域或存储库中实现子实体操作吗?

不,存储库仅操作聚合。

2.使用实体框架加载与项目相关的所有子实体或导航到它们是可以的。使用 .include(..) 加载根即可完成工作。但是更新一个 ItemActivity 甚至删除一个 ItemActivity 呢?从集合中删除它们不会持续存在。

  Item.getActivity().updateRemark("...");
  ItemRepository.store(Item);

3.假设我必须找到一个时间跨度内的所有活动。

如果需要按范围查询,最好将 ItemActivity 设为另一个聚合根。较小的聚合有助于这种情况。

4.Is there a sample covering this topic.

著名的有效聚合设计。有一些示例代码(尤其是在第 1 部分中)与您的案例密切相关。

于 2013-10-31T12:07:03.440 回答