我的问题是
聚合根实体是否可以具有将调用存储库的方法?
Can Aggregate root entity have method in which it will call a Repository ?
我知道不应该,但想得到证实,因为Eric的书也没有明确说出什么:(
I know it should not but want to get confirmed as Eric's book is also not saying anything clearly :(
还有什么我可以从中获得域驱动设计的单元测试示例的?
one more thing where can i get unit testing example for domain driven design ?
推荐答案这是一个宗教问题。 有些人认为这样做没有问题,而另一些人则认为这样做是异端。
This is a bit of a religious question. Some see no problem with this, while others might believe it is heresy to do so.
尽管我通常总是将存储库远离域模型(并有一个上游服务对象处理该存储库),我有一个需要一个项目,使该存储库可以从域模型访问。这是由于域对象需要基于以下内容来检索特定数据:业务逻辑=>使用规范对象/ Linq来实现nHibernate(如何过滤属于该域对象的数据的责任和知识)和/或性能原因。
While I've normally always kept my Repository away from my Domain Model (and had an upstream service object deal with the Repository), I have had a project that "required" having the Repository accessable from the Domain Model. This was due to the Domain object needing to retrieve specific data based on business logic => using specification objects/Linq to nHibernate (the responsibility and knowledge of how to filter data belonged to that Domain Object) and/or performance reasons.
一个警告周围的方法是如何获取对Domai的存储库的引用n对象-在那种情况下,我通过IOC工具使用了构造函数注入。
A caveat around doing this is how to get the reference to the Repository to the Domain object - in that case I utilized Constructor injection with an IOC tool.
是否应该执行此操作实际上取决于您的解决方案/用例/使用的技术等...
Whether you should do this or not really depends on your solution/use case/technologies being used etc...
更多推荐
可以汇总根实体调用存储库
发布评论