使用Prism时将应用程序的零件拆分为自己的程序集 [英] Splitting app's parts in their own assemblies when using Prism

查看:89
本文介绍了使用Prism时将应用程序的零件拆分为自己的程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MVVM 方法鼓励(或只是提供了可能性)将WPF或Silverlight应用程序拆分为 Model ViewModel 查看项目,以便这三个项目都可以存在于各自的程序集中.

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.

另一方面,使用 Prism (在我的例子中,MEF作为依赖注入容器),可以构建一个模块化应用程序,该应用程序分为一组功能单元(称为模块) ),并且在这种情况下,每个单元都是单独的组件.
我是对的,在这种情况下,我们只能在自己的程序集中分离 Model ,但是 View ViewModel 应该位于一个组件代表一个功能模块?

Using Prism (and, in my case, MEF as a Dependency Injection Container), on the other hand, one can build a modular application 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?

推荐答案

首先,模块不是相等的程序集.您可以在多个装配体之间(包括模型,视图和视图模型)分布模块的零件.尽管通常将与模块相关的类放在一个DLL或XAP文件中(对于Silverlight,如果您的模块是单独的Silverlight应用程序).

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).

根据您的情况,如果模型是可以由多个模块使用的共享实体,则Prism鼓励将其放置在所谓的基础结构"程序集中,该程序集保留共享的非模块特定逻辑.否则,将MVVM零件放在一起可能是一个好主意,因为它们可以解决常见的业务任务.将来,如果您需要替换MVVM部件之一的实现,则只需添加一个新部件并调整容器的映射即可.

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.

这篇关于使用Prism时将应用程序的零件拆分为自己的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆