处理聚合中持久存在多个数据库的实体的好方法是什么
我正在处理一个设计问题,我确信这个问题有一个简单的答案和/或之前已经解决了。我已经阅读、思考和寻找解决方案很长一段时间了,但似乎没有什么真正有意义的。
问题的要点是,我正在处理一系列遗留系统和数据库,并且我正在尝试采用 DDD 方法来构建新应用程序并替换旧应用程序。核心问题是,虽然我的域实体、值对象和聚合具有商业意义,但当我考虑持久性时,我遇到了一个大问题……聚合中的实体当前保存在多个数据库中。
例如,假设我有实体 A、B 和 C,其中 A 是聚合根。我有一个 A 的存储库,并且我正在围绕 NHibernate 会话使用工作单元来实现持久性。只要 A、B 和 C 都保存到单个服务器/数据库,一切都很好。然而,就我而言,A 和 B 可能位于一台服务器/数据库上,而 C 可能保留在完全不同的服务器/数据库上。
我意识到传统智慧可能建议人们永远不应该这样做,但我正在处理一个遗产。当然,随着时间的推移,我可能会将数据层重构为更符合逻辑的东西,但现在我陷入了困境。我怀疑我在某种程度上总是会遇到这个问题,而且我不禁想到其他人已经跨过了这座桥。
简而言之,我有一个自行开发的 C# 框架,其中包括用于持久性的 Fluent/NHibernate、用于 IoC 的 Unity 以及采用标准(或至少是可识别的)存储库和工作单元模式。至于数据库,我正在处理 MS SQL Server 和 Oracle。
有什么想法吗?
I'm dealing with a design problem that I'm sure has a simple answer and/or has been solved before. I've been reading, thinking, and searching for solutions for quite a while, but nothing seems to really make sense.
The gist of the issue is that I'm dealing with a series of legacy systems and databases and I'm trying to take a DDD approach to building new apps and replacing older ones. The core issue is that while my domain entities, value objects, and aggregates make business sense, when I consider persistence I have one big problem... the entities within an aggregate are currently persisted in multiple databases.
For example, let's say I have entities A, B, and C where A is the aggregate root. I have a repository for A and I'm employing the Unit Of Work around an NHibernate session for persistence. All is great and fine as long as A, B, and C are all persisted to a single server/database. In my case, however, A and B might be on one server/database and C might be persisted on a completely different server/database.
I realize that conventional wisdom might suggest that one should never do this, but I'm dealing with a legacy. Sure, in time I'll likely refactor the data tier to something more logical, but for now I'm stuck. I suspect that I'll always have this problem to some degree and I can't help but to think that others have crossed this bridge.
In short, I have a homegrown framework in C# consisting of Fluent/NHibernate for persistence, Unity for IoC and employing standard (or at least recognizable) Repository and Unit Of Work patterns. As for databases, I'm dealing with MS SQL Server and Oracle.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
聚合根不应存在于多个数据库中。
Greg Young 在此处讨论了同一问题。
一些像这样 是你应该做的。
Aggregate root shouldn't live across multiple databases.
Greg Young talks about this same issue here.
Something like this is what You should be doing.