问题标签 [eventaggregator]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
.net - 发布者对事件聚合器设计模式的说明
我想澄清事件聚合器设计模式中“发布者”的角色。
我当前的解决方案处理 .NET 数据事件,例如发生在 XmlDocument 中的 XmlNode 事件。
问题:在事件聚合器设计模式中,发布者被认为是什么?
c# - 事件聚合器与服务
在使用 Prism 和 MEF/Unity 开发相当大的应用程序时,我总是会在使用事件、服务或两者之间进行选择。而且我无法决定什么是最有用的。也许我的架构有问题(因为这个决定不应该首先做出)但我不明白是什么。
这是一个典型的例子:我的应用程序有一个主窗口和许多由模块或用户操作按需创建的从属窗口。应用程序决定从属窗口的 chrome 的外观和行为,记住窗口位置等,而内容本身是在模块中的某个位置创建的。还有很多用户操作导致隐藏/显示/带到窗口前面。为了实现这一切,我目前有一个监听 CreateWindow/SetWindowState/.. 事件的 WindowManager 服务。
这有以下好处:
- 使用它的类只知道 IEventAggregator(它们已经在大多数时间用于其他事件)和 WindowManager 消耗的事件,而不是 WindowManager 本身
- 像 ViewModels 这样的类不直接处理窗口。相反,他们通过标题或 id 以及封装了所需内容的小事件类来引用它们。
- 不需要单独的 IWindowManager 接口只是为了在测试中模拟它
和提款:
- WindowManager 可以完全独立使用,但现在它需要订阅事件。或者可能更好,其他一些班级必须处理这个问题。
- 将其扩展为显示模式对话框有些棘手:如果 VM 触发事件以显示对话框,则 Publish 调用仅在对话框关闭后返回至关重要
- WindowManager 可作为服务使用,它位于 CompositionContainer 中,为什么不直接使用它呢?
直接使用该服务只会改变收益/提款,而且似乎没有明显的赢家。
问题:你会使用什么作为指导规则来选择一个或另一个,或者你宁愿总是只选择一个,还是两者都选?我的应用程序设计中是否有什么特别错误的地方需要我做出这个决定?
c# - When is it ok to combine 2 viewmodels into 1 instead of using some form of viewmodel-viewmodel communication?
I have 2 viewmodels that each have their own view.
the first view model has 3 properties being displayed by the view:
the second view model has only 1 property being displayed by its view:
There is a 1 to many relationship between the PolicyType
and the TypeOfInvestmentFund.
Both of these view models and their views are being displayed as user controls inside a parent form.
The available choices for the TypeOfInvestmentFund
is dependent on which PolicyType
is selected in the other view.
To me this feels like these 2 view models could be combined, because
a) they are clearly somewhat coupled
b) the controls are both so small and simple that joining them will not create a complex and unmanageable object.
However this data is fairly unrelated; unrelated enough that the user would still want the data visible in seperate parts of the form (and therefore be placed on seperate views).
I personally feel that combining these 2 view models and having 2 seperate views connect to it to display different parts of it is a lot less overhead then managing the communication between the 2 objects.
I could however create loosely coupled events with the Prism Event Aggregator, and although I have never done this it is probably not much to manage, and keeping these 2 view models seperate would preserve seperation of concerns. Furthermore if other controls were to appear later on in development that also need this information, I cant keep absorbing them, so starting an event aggregator at this stage would prevent rework as the events would be available already to subscribe to. It is still more work then just combining the view models.
Which one of these 2 is 'more correct'? I understand its a judgement call, but I can't decide so I'm looking for opinions to help me make up my mind.
javascript - 相关的 Backbone.js 视图应该相互引用,还是只通过事件进行对话?
我有一个Collection
为Models
. 每个模型都有一个DisplayView
始终可见。还有一个只有在单击EditView
关联时才可见。DisplayView
DisplayView
和EditView
出现在不同的父视图中。现在我正在使用“事件聚合器”模式来告诉我的应用程序在单击EditView
a 时呈现DisplayView
。此处描述的模式:http: //lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/
当单击其中一个时,DisplayView
它会触发一个事件,该事件的父级EditViews
侦听。当它接收到这个事件时,它会EditView
根据触发事件的模型呈现适当的 。
这适用于我的大多数应用程序,但当我想根据应用程序EditView
中相关项的绝对位置更改位置时尤其麻烦DisplayView
。它不是DisplayView
直接控制 的位置EditView
,而是触发“请重新定位到这些坐标”事件。这种直接的通信感觉不像是应该向整个应用程序广播的东西。我开始怀疑对于我的情况,我是否应该将适当的引用EditView
作为每个属性的属性,DisplayView
而不是将它们解耦。
正如我所说,问题在于它们是在不同的父视图中呈现的。DisplayViews
get 中渲染,HeaderView
而getEditViews
中渲染ContentView
。
其他人如何处理这样的情况?在EditView
某些方面属于DisplayView
,但这与我的应用程序 DOM 的结构方式不匹配。假设我确实在每个EditView
和之间创建了直接链接DisplayView
,我将如何处理 的显示/隐藏EditView
?是否DisplayView
还需要对ContentView
容器的引用,它将使用适当EditView
的参数显式呈现?
silverlight - silverlight mvvm 应用程序中的中介文件
在 silverlight-MVVM 应用程序中,我们必须使用某种调解器/甚至聚合器文件..在不同的视图模型之间进行通信。
但我可以看到这些文件维护对象列表(或字典)......
这不会使用大量内存...?如果是 Web 应用程序(如果是 WPF,那没关系)......这是推荐的吗?
任何帮助,将不胜感激。提前致谢!
wpf - 将多个参数传递给 Prism 的 EventAggregator
我正在使用 Prism 的 EventAggregator 在我的模块的 ViewModel 之间进行松散耦合的通信。我在ViewModelA中有几个属性(例如 FirstName、LastName),当它们的值发生变化时需要更新ViewModelB中的属性。我目前的解决方案包括:
ViewModelA使用 FirstName 的新值作为有效负载发布事件:
ViewModelB订阅了 Event 并相应地更改其 FirstName 属性:
这适用于单个属性。它不适用于多个不同的属性,因为ViewModelB不知道 ViewModelA 上的哪些属性发生了变化。ViewModelB 知道新值是什么,但它不知道要更新它的哪些属性。
我可以为每个属性创建单独的事件,但这似乎是重复的。只使用一个事件似乎更干净。理想情况下,在发布事件时,ViewModelA 应该告诉 ViewModelB 哪个属性发生了变化。我怎样才能做到这一点?
wpf - 通用事件聚合器?
我们要触发事件,事件名称保存在 SQL Server 中
在 SQL Server 中,您会发现 ApplicationExitRequestEvent 当我们单击菜单按钮时,我们将从 MenuItem 中获取字符串
有可能吗?使用 PRISM 和 MVVM - WPF - .NET 4.0
c# - 试图了解如何在 UI 线程上调用它
我正在研究不同的开源项目,以了解人们如何以不同的方式处理同一个问题。这次是事件聚合器,特别是 Caliburn.Micro 的聚合器。
我注意到 Rob 说如果没有提供线程,EA 将编组到 UI 线程。该行具体是:
然后进一步:
我不明白他怎么能说这将在 UI 线程上调用,是否所有操作都在 UI 线程上调用,除非您指定一个不是?(顺便说一句,您可以指定调用哪个操作,上面的行只是在没有提供操作的情况下)。
wpf - 通过在 wpf 中使用 Eventtaggregator 从视图模型到视图模型的 PRISM MEF 通信
我正在尝试使用 WPF 和 PRISM 创建 WPF 应用程序。我也在使用 MEF 和 mvvm。是否有可能有 2 个视图模型可以通过使用事件聚合器相互通信?例如。在视图模型 A 中发布并在视图模型 B 中订阅?如果是这样怎么办?我已经构建了一个具有多个视图模型的程序,其中一些视图模型应该相互通信,但是如果我使用 eventtaggregator 在 Viewmodel A 中发布,A 在 viewmodel B 中的订阅将永远不会被识别为属于同一个 eventtaggregator,所以我不能更新连接到视图模型 B 的视图。
silverlight - Silverlight 挂在 Prism 的 EventAggregator 订阅方法上
我在 Silverlight 中使用 Prism 的事件聚合器,并且在订阅时遇到了困难。当代码点击订阅方法时,它只是挂起,永远不会进入下一行代码。如果我分解代码, _eventAggregator.GetEvent() 似乎返回事件的有效实例。代码肯定挂在“订阅”上。我在这里做错了什么?JobCompletedEvent 在另一个库中声明(这是该库的依赖项)。