这是一种可能性。与大多数架构问题一样,答案是:它取决于。
在这种情况下,这取决于您的整体架构如何以及如何构建有界的上下文。如果他们有相似的聚合持久化到同一个表(也就是因为上下文而不同),那么有可能有不同的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
发布评论