【发布时间】:2014-06-27 08:42:05
【问题描述】:
我目前正在尝试发现 聚合根 背后的想法以及它们与存储库的关系。
给出以下域实体:
public class Country {
public string Name { get; set; }
public ICollection<City> Cities { get; set; }
}
public class City {
public string Name { get; set; }
}
我想我正确地将 Country 标识为 City 的 聚合根,因为在我的域中,不应该有任何城市不在一个国家内。应该只能通过国家/地区将新城市添加到数据存储中,如果国家/地区被删除,则内部的每个城市也应该被删除。
现在,这样的Country Repository会是什么样子? Country Aggregate Root 是什么样的?域内是否有 CityRepository(即使没有相关国家,我也可以将城市添加到数据库中!)? CountryRepository 内部是否有 CountryRepository(国家需要以某种方式填充其城市?或者这是存储库的工作?)
【问题讨论】:
标签: c# design-patterns domain-driven-design ddd-repositories aggregateroot