使用 Prism 时将应用程序的各个部分拆分到各自的程序集中

发布于 2024-10-20 01:54:32 字数 370 浏览 1 评论 0原文

MVVM 方法鼓励(或只是提供可能性)将 WPF 或 Silverlight 应用程序拆分为 ModelViewModelView 项目,因此这三个项目都可以存在于自己的程序集中。

另一方面,使用 Prism(在我的例子中,MEF 作为依赖注入容器),可以构建一个模块化应用程序,该应用程序分为一组功能单元(称为模块),每个功能单元在这种情况下,单元是一个单独的组件。
我说得对吗,在这种情况下,我们只能在自己的程序集中分离一个模型,但视图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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞳孔里扚悲伤 2024-10-27 01:54:32

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

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

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.

长途伴 2024-10-27 01:54:32

是的,Prism 鼓励您将所有内容(模型、视图和视图模型)放入一个独立的功能模块中。

无论如何,我强烈不建议您将视图和视图模型拆分为单独的项目。这是因为它们紧密耦合在一起并且并行开发。

对于如何组织 MVVM 应用程序,有两种推荐的方法。首先是当您按层组织项目并将视图和视图模型放入项目内的单独文件夹中时。其次,当您按功能创建文件夹时,不要将视图和视图模型分开,即它们并排位于同一文件夹中。我个人选择第二个,因为正如我提到的,它们总是一起开发和维护,这样很容易找到相应的视图或视图模型。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文