ef上下文+数据库模式+ DDD BoundedContext [英] ef context + database schema + DDD BoundedContext

查看:441
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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