ef context + database schema + DDD BoundedContext

拥有回忆 提交于 2019-12-25 12:21:58

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/23949971/ef-context-database-schema-ddd-boundedcontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!