我试图从架构和设计角度理解Event Aggregator模式.我之前从未在WPF中使用Prism,但我正在研究它如何在MSDN上运行.
在我看来,对于每个事件,用户必须创建一个扩展CompositePresentationEvent的新事件对象.似乎新事件对象除了从它继承的功能之外没有其他功能(它通常没有自己的代码).
例如:
AddNewStuffEvent看起来像:
public class AddNewStuffEvent : CompositePresentationEvent<Object> {} //The end of the class
对于HealthChangeEvent:
public class HealthChangeEvent: CompositePresentationEvent<Object> {} //The end of the class
对于BookFlipEvent:
public class BookFlipEvent: CompositePresentationEvent<Object> {} //The end of the class
对于BookCloseEvent:
public class BookCloseEvent: CompositePresentationEvent<Object> {} //The end of the class
对于BookOpenEvent,BookTearEvent等的每个小事件,这可以永远持续下去.因此,在特定的命名空间文件夹中,将有大量的事件类,并且Event Aggregator将加载所有这些事件对象在运行时.那就是,每个小小的活动都需要空课?这是怎么回事?有什么比这更好的方法呢?
解决方法:
是的,每个事件类型都需要自己的类,您必须定义它.
It also appears that the new event object has no functionality other than those it inherited from
目的只是为活动提供强有力的打字.这样可以更轻松地编写代码来订阅它们.即,订阅代码可以写成:
aggregator.GetEvent<AddNewStuffEvent>().Subscribe(Handler);
这是一种更好的替代方法,例如依赖于“magic strings”形式的聚合器.GetEvent(“AddNewStuffEvent”).订阅(处理程序)(在编译时无法验证).
原文地址:https://codeday.me/bug/20190629/1331066.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。