ef上下文+数据库模式+ DDD BoundedContext

编程入门 行业动态 更新时间:2024-10-24 08:29:02
本文介绍了ef上下文+数据库模式+ DDD BoundedContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我知道至少EF 6支持多个DbContexts。这可以用于建模 BoundedContext 。我做了一些google搜索,但找不到这个问题的确切答案。为不同的DbContexts / BoundedContext使用不同的db模式是否可取?我知道ORM抽象出持久性机制,但我个人可以看到shemas和ddd / ef上下文之间的并行。

解决方案

这是一种可能性。与大多数架构问题一样,答案是:它取决于。

在这种情况下,这取决于您的整体架构如何以及如何构建有界的上下文。如果他们有相似的聚合持久化到同一个表(也就是因为上下文而不同),那么有可能有不同的DbContexts可能是一个好主意,因为您可以单独进行演进。

注意,您可能会在有界的上下文之间引入隐藏的约束和依赖关系。

如果您的有界的上下文有非常不同的聚合,那么不需要使用不同的DbContexts,您可以共享相同的。

另一个可能考虑的选项是使用不同的DbContext进行阅读和写作。它还允许您单独演变您的模型。 (这更多是CQRS方法)

I understand that at least EF 6 supports multiple DbContexts. This can be used to model BoundedContext. I did some google searches but could not find a definitive answer to this question. Is it advisable to use different db schemas for different DbContexts/BoundedContext? I know that ORMs abstract away the persistence mechanisms but I personally can see parallels between shemas and ddd/ef contexts.

解决方案

It is a possibility. As with most architectural questions, the answer is: it depends.

In this case, it depends on how your overall architecture is and how your bounded contexts are structured. If they have similar aggregates that are persisted to the same tables (that is, they're different because of the context), it might be a good idea to have different DbContexts because then you can evolve them separately.

Note though that you may be introducing hidden constraints and dependencies between your bounded contexts.

If your bounded contexts have very different aggregates, then there's no need to use different DbContexts and you can just share the same one.

Another option you might consider, is using a different DbContext for reading and writing. It also allows you to evolve your model separately. (that's more of a CQRS approach though)

更多推荐

ef上下文+数据库模式+ DDD BoundedContext

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

发布评论

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

>www.elefans.com

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