Modular applications with Entity Framework Code Only and ASP.NET MVC

别等时光非礼了梦想. 提交于 2019-12-07 01:13:33

问题


By modular applications I mean applications in which base functionality and data model can be extended without modifying core application code.

It's a popular approach with eg. open source CRMs like SugarCRM or VTiger.

This approach may be followed in asp.net mvc application using Areas or (portable areas from MVC contrib) which allow adding new controllers and views in separate assemblies, without impacting core dlls.

The problem arises when one wants to extend the base application's data model. It's not possible in any practical sense with entity framework where the model definition is centralized in the Edmx file. This approach doesn't allow adding a new table that would reference some base module table in a new assembly.

I've noticed, that the Orchard CMS achieves full modularity by using nHibernate (which is telling, given they have Microsoft backing and the project was meant as a technology showcase). Nhibernate allows such modularity thanks to the POCO approach. Each entity/table is defined in a separate file which obviously is the way to go with modular applications.

There is, however, a hope with Entity Framework Code Only approach, which generates Edmx model in runtime using POCO definitions. Has anyone tried this approach to distribute the data model's definitions in a separate, pluggable projects?


回答1:


I have achieved this using EF Code First and a combination of GUI extension points on the core module. It resulted in:

  • Each module is treated as a standalone application (except for GUI)
  • Each module has it's own database (as code first drops & recreates database)
  • Each module may duplicate needed data in another module
  • Each module is a service
  • Each module can extend the GUI through core extension points via an IoC container
  • Modules can communicate with each either via asynchronous messaging (nServiceBus) and synchronous RPC (WCF)

Please note that this is an enterprise application that we designed for SOA.

With EF Code First, if you manage your database manually (ie. don't drop & recreate), you could take some concepts above and simplify it. You may need a custom IDatabaseInitializer to support it but it should be possible.



来源:https://stackoverflow.com/questions/5142209/modular-applications-with-entity-framework-code-only-and-asp-net-mvc

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