域模型可以知道存储库吗? [英] could domain models be aware of repositories?

查看:79
本文介绍了域模型可以知道存储库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于某些域逻辑实现实体可能需要访问回购协议以更新/删除自身或任何相关实体。

May be for some domain logic implementation entities need access to repo for update/delete of self or any related entity. Does this sound right ??

推荐答案

不是,至少在以 domain标记的问题上不是这样吗?驱动设计 标签。
肯定地,Active Record模式有权在某些系统中使用,并且某些人发现强耦合很有用,但是在DDD中,建议的方法是显式使用存储库:

No, it doesn't, at least for the question tagged with "domain-driven-design" tag. Definitely, Active Record pattern has a right to live in some systems and some people find strong coupling useful, but in DDD the proposed way is to use repositories explicitly:

Evans DDD,第152页:对于需要全局访问的每种对象类型,创建一个对象,该对象可以提供所有对象在内存中的集合的错觉这种类型的。 «...»仅为实际需要直接访问的AGGREGATE根提供存储库。让客户专注于模型,委派所有对象存储和对存储库的访问。

Evans DDD, p.152: For each type of object that needs global access, create an object that can provide the illusion of an in-memory collection of all objects of that type. «...» Provide REPOSITORIES only for AGGREGATE roots that actually need direct access. Keep the client focused on the model, delegating all object storage and access to the REPOSITORIES.

因此,在DDD中,存储库不仅封装了访问数据库所需的基础结构代码,而且还封装了对象必须被存储和加载。

So, in DDD, repository not only encapsulates the infrastructure code, required to access the database, but the whole idea that the objects must be stored and loaded.

如果您要执行一些涉及从数据库保存和加载的复合操作,则引用了存储库的服务 是最好的候选人。

If you are doing some compound actions which involve saving and loading from the database, then the services that have references to the repositories are the best candidates.

这篇关于域模型可以知道存储库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆