可以汇总根实体调用存储库

编程入门 行业动态 更新时间:2024-10-23 04:57:22
本文介绍了可以汇总根实体调用存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题是

聚合根实体是否可以具有将调用存储库的方法?

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...

更多推荐

可以汇总根实体调用存储库

本文发布于:2023-11-28 16:30:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643134.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!