wpf - "WPF services"到底是什么?

标签 wpf mvvm service

有人在 answer to a stackoverflow question 中告诉我MVVM 模式的“两把大炮”是 1) 附加行为和 2) 服务 .我认为他的意思是“ WPF 服务 ”,我发现该短语以下列方式使用:

PresentationFoundation.dll defines the WPF controls types, animation and multimedia support, data binding support, and other WPF services.

Many of these WPF services ( de-coupled eventing, rich databinding, styling, resources, etc.) are software development best practices that converge in a single, declarative UI stack.

You will understand the motivation behind WPF, learn the syntax of XAML, examine the core programming model, and survey several WPF services.



我什至没有提到“WPF 服务”这样的 WPF 书籍,所以这只是一个表示“ WPF 功能 ”的词,例如解耦事件、丰富的数据绑定(bind)、样式等“WPF 服务”一词背后的其他内容?

最佳答案

Martin Fowler 在他的 Dependency Injection 中描述了服务是什么。文章。简而言之,服务是提供其他对象使用的功能的对象。在讨论模式时,您会发现该术语被大量使用 Inversion of ControlService Locator .

为了使这个主题具体化,让我们考虑一下如何在 MVVM 模式中显示消息框。调用 MessageBox.Show() 会很糟糕,Ray。这将 ViewModel 与 UI 架构紧密联系在一起,并使 ViewModel 难以测试。相反,一种解决方案是使用服务,我们将其称为 IDisplayMessage。该服务以某种方式(通过上述两种模式之一)提供给 ViewModel,并且该服务用于“显示”消息。在正常操作期间,此服务的具体版本将调用 MessageBox.Show(),但在测试期间,我们可以提供不同的具体版本(测试替身),其行为不同(通常是 noop,或者如果我们确保 ViewModel 显示消息,一个记录调用的版本,以便我们可以断言它发生了)。 Onyx (免责声明:我是作者)仅提供这样的服务,以及向您的 ViewModel 提供此服务(和其他服务)所需的基础设施。

更新:自从做出此回应后,我写了一篇博文 Services: Your ViewModel Deathstar ,它很好地涵盖了该主题。这是“系列”帖子的一部分,读者也可能对第一篇文章感兴趣Behavior - Your Trusty ViewModel Bazooka .

关于wpf - "WPF services"到底是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/925017/

相关文章:

wpf - 如何绑定(bind)到 XAML、WPF 中的附加属性

wpf - 从选项卡内部将选项卡添加到选项卡控件

安卓 : cancel alarms when service is uninstalled

unit-testing - Angular 服务测试有什么问题?

android - 绑定(bind)服务与存储库

c# - WPF 防止数据网格在窗口大小调整时自动调整大小

c# - 我如何从框架中获取页面实例?

c# - UI 不更新 bool 更新

wpf - 在这种情况下推荐最佳方法

design-patterns - View/ViewModel 循环依赖引用是否合适?