【发布时间】:2013-04-04 13:45:42
【问题描述】:
我想谈谈您如何看待存储库模式。
在“旧”域概念(例如来自P of EAAA)中,存储库应该像“内存中的集合”,所以它应该总是返回相同的类型,所以如果你需要一个投影,你必须制作它出,所以投影将在服务层进行,对吧?还是可以直接进入“Domain”项目?
例如
public class CustomerRepository
{
//Constructor accepts an IRepository<Customer>
public IQueryable<Customer> GetAllDebtors()
{
//Use IRepository<Customer> here to make the query
}
}
相反,在 DDD 中,存储库,尤其是与 CQRS 结合使用,可以直接返回投影类型,因为存储库成为非规范化服务,对吧?
例如
public class CustomerDenormalizer
{
//Constructor *could* accept an IRepository<Customer>
public IQueryable<Debtor> GetAllDebtors()
{
//Use IRepository<Customer> here to make the query and the projection
}
}
【问题讨论】:
标签: c# domain-driven-design repository-pattern