像使用字符串事件名称的旧 CAB 事件系统一样使用 Prism EventAggregator
我看到 Prism 的事件聚合器总是并且只与 GetEvent 一起使用,这很奇怪。我习惯了旧的 CAB 事件系统 - 现在使用 Marlon Grech 的 Mediator 实现 - 我在其中定义了字符串常量,这样如果数据是简单的 int 或值类型,我就不必创建额外的类来触发/包装我的数据。
[MediatorMessageSink(MediatorMessages.AddSchoolclass, ParameterType = typeof(int))]
public void OnSchoolclassAdded(int schoolclassId)
{
// do stuff with schoolclassId
}
我怎样才能用 Prismn 的 eventaggregator 做同样的事情
I see Prism`s eventaggregator always and only used with GetEvent which is very odd. I am used to the old CAB event system - now using Mediator implementation from Marlon Grech - where I have defined string constants that way I do not have to create extra classes to fire/wrap my data if its a simple int or value type.
[MediatorMessageSink(MediatorMessages.AddSchoolclass, ParameterType = typeof(int))]
public void OnSchoolclassAdded(int schoolclassId)
{
// do stuff with schoolclassId
}
How can I do the same with the eventaggregator from Prismn
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以声明一个事件类用于所有聚合事件,并传递一个字符串作为其有效负载,但我真的不推荐这种方法。 Prism 开发人员会发现这非常令人困惑。
事件聚合器使用与旧 CAM 不同的架构。当我进行更改时,我对事件对象的需求也不满意。但从那以后我就被这种方法所吸引——事件对象基本上是我使用 ReSharper 模板生成的一行代码。我如此喜欢它的原因是它给了我一个地方来放置我可能需要的任何与事件相关的逻辑。
You could declare a single event class to use for all of your aggregate events, and pass a string as it's payload, but I wouldn't really recommend that approach. Prism developers would find it very confusing.
The Event Aggregator uses a different architecture than the old CAM. I wasn't happy either about the need for an event object when I made the change. But I've since been sold on the approach--the event object is basically a one-liner that I generate using a ReSharper template. The reason I like it so much is that it gives me a place to put any logic I might need to go along with the event.