MEF and MVC 3 - how to load embedded views dynamically from mef container?

后端 未结 1 1490
伪装坚强ぢ
伪装坚强ぢ 2021-02-08 02:44

I\'m building an MVC 3 application where MEF is used. The main idea is to have plug-in mechanism where models, controllers and views are loaded dynamically during runtime from m

相关标签:
1条回答
  • 2021-02-08 03:00

    Here is a thought.

    If you follow the View Model Pattern then instead of sending the DTO's straight to the view use a ViewModel that is would be located in the same assembly as the View.

    So Instead of:

    UserDTO model is located in Module1.Data.dll ShowUserController.cs is located in Module1.Web.dll/Controllers/ Index.cshtml is located in Module1.Web.dll/Views/ShowUser (with declared @model Module1.Data.UserDto)

    You would have:

    UserDTO model is located in Module1.Data.dll ShowUserController.cs is located in Module1.Web.dll/Controllers/ UserVM located in Module1.Web.dll/ViewModels Index.cshtml is located in Module1.Web.dll/Views/ShowUser (with declared @model Module1.Web.ViewModels.UserVM)

    Have the Controller Map your DTO's to ViewModels

    See AutoMapper to help with the Mapping

    0 讨论(0)
提交回复
热议问题