开发者

Splitting app's parts in their own assemblies when using Prism

The MVVM approach encourages (or just gives the possibility to) splitting a WPF or Silverlight application into Model, ViewModel and View projects so all three could exist in their own assemblies.

Using Prism (and, in my case, MEF as a Dependency Injection Container), on the other hand, one can build a modular applicat开发者_Go百科ion that is divided into a set of functional units (named modules) and each unit, in this case, is a seperate assembly.

Am I right that in this case we can separate only a Model in an its own assembly, but View and ViewModel should sit in one assembly, representing one functional module?


First of all, module is not equal assembly. You can spread a module's parts between several assemblies (including Models, Views and ViewModels). Although, usually you place classes related to a module together in one DLL or XAP file (in case of Silverlight if your module is a separated Silverlight application).

As of your case, if a Model is a shared entity which can be used by several modules, Prism encourages to place it in so called Infrastructure assembly that keeps shared non-module specific logic. Otherwise, it could be a good idea to place MVVM parts together, since they solve common business tasks. In the future, if you need to replace implementation of one of the MVVM's parts, you can do it just adding a new one and adjusting container's mapping.


Yes, Prism encourages you to put everything (models, views and view models) into one self-contained functional module.

In any case, I would strongly NOT recommend you splitting views and view models into separate projects. This is because they are tightly coupled together and are developed side-by-side.

Well, there are two recommended approaches on how you organize you MVVM application. First is when you organize your project by layers and put you views and view models into separate folders inside a project. Second, when you create folders by feature and don't separate views and view models, i.e. they lie in the same folder side-by-side. I personally choose the second one because, as I mentioned, they are developed and maintained always together and this way it is very easy to find corresponding view or view model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜