IdentityMap 属于哪里:UnitOfWork 还是 Repository?

发布于 2024-08-12 15:47:56 字数 372 浏览 2 评论 0原文

如果我实现一些简单的 OR/M 工具,我应该把恒等映射放在哪里?显然,每个存储库都应该有权访问自己的身份映射,因此它可以注册加载的对象(或者也许 DataMapper 是在 IdentityMap 中注册对象的那个?)。

当我提交工作单元时,我还需要访问身份映射以查看哪个实体是脏的,哪个实体是干净的(或者我又错了,有一些外部对象调用我的 UnitOfWork 类的 RegisterClean/RegisterDirty 方法?然后这是什么对象?)。

这是否意味着我应该将 IdentityMap 实现为一个完全独立的对象,其中包含每个实体类型的内部 IdentityMap?

对于 IdentityMap、Repository 和 UnitOfWork 如何一起工作真的很困惑。

If I implement some simple OR/M tool, where do I put identity map? Obviously, each Repository should have access to its own identity map, so it can register loaded objects (or maybe DataMapper is the one who registers objects in IdentityMap?).

And when I commit unit of work, I also need to access the identity map to see which entity is dirty and which is clean (or I am wrong again and there is some outer object which calls RegisterClean/RegisterDirty methods of my UnitOfWork class? Then what object does this?).

Does this mean that I should implement IdentityMap as a completely independent object which contains inner IdentityMaps for each entity type?

Really confused about how IdentityMap, Repository and UnitOfWork work all together.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萝莉病 2024-08-19 15:47:56

通过我们的 .NET O/R Mapper, LightSpeed,我们放置了身份工作单元类内的映射。这对我们来说非常有效,并且感觉很自然,因为它在工作单元的生命周期中有效地充当用于查询目的的 1 级缓存。

通常,为您的 Repository 类注入或以某种方式提供 UoW,以便您拥有有效的范围和查询网关。

我希望这有帮助。

With our .NET O/R Mapper, LightSpeed we placed the identity map inside the unit of work class. This has worked very well for us and feels quite natural as it effectively acts as a level 1 cache for querying purposes during the unit of work's life.

Generally, inject or somehow provide a UoW for your Repository class so that you have an effective scope and gateway to querying.

I hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文