Tag: eventaggregator

EventAggregator和ServiceLocator问题

我开始使用Prism和MVVM开发一个WPF项目,我正在尝试使用eventAggregator但是,当执行下面的行时会引发exception: IServiceLocator ob = ServiceLocator.Current; // This line causes a Null pointer exception EventAggregator = ob.GetInstance(); 但是我无法理解我做错了什么,也许这是一件非常简单的事情,但我已经在努力了几个小时。 希望有人可以帮助我,提前谢谢

Caliburn Micro构造函数注入失败

我正在学习Caliburn Micro并尝试使用官方网站上的EventAggregator 。 但是,我得到了一个例外 “没有为此对象定义无参数构造函数。” 消息本身很清楚,但示例中也没有包含无参数构造函数。 如果我添加一个,带有参数的构造函数不会被命中, IEventAggregator仍未正确注入。 添加无参数构造函数后,这是我的发布者VM(没有它,将抛出exception): public MainViewModel() { } public MainViewModel(IEventAggregator ea) : this() { eventAggregator = ea; } 这是我正在使用的引导程序: public class AppBootstrapper : Bootstrapper { private readonly SimpleContainer container = new SimpleContainer(); protected override void Configure() { container.Singleton(); } } 这是CM的例子: // Creating the EventAggregator as a singleton. public class […]

Prism – EventAggregator.GetEvent 。订阅() – 使用generics和约束

我有一个问题订阅事件Aggregator事件作为prism框架的一部分。 如果我使用像 eventAggregator.GetEvent().Subscribe(MyMethod) 然后一切正常,我的方法在事件发布时触发。 但是,当移动到除I string之外的更复杂的对象时,我遇到了问题。 我有一堆类,它们都来自一个接口(IRequest),例如 我的事件类设置如下 public class MyEvent : PubSubEvent<MyClass> where TRequest : IRequest {} 我有一个generics类(MyClass)在其中使用IRequest的对象 – 再次,在这一点上似乎一切正常。 现在,假设我发布了一个使用其中的对象Profile的MyClass事件: eventAggregator.GetEvent<MyEvent>().Publish(myProfileObject); 在我的订阅中,我想要一个可以捕获MyEvent的所有事件的方法 – 与T是Profile还是从IRequest派生的其他对象无关 – 这是我似乎遇到问题的地方。 在下面的例子中,第一个工作,但第二个没有 – 我理想的是喜欢使用类似于第二个的东西。 eventAggregator.GetEvent<MyEvent>().Subscribe(test1); void test1 (MyClass obj) { //Some stuff here } eventAggregator.GetEvent<MyEvent>().Subscribe(test2); void test2(MyClass obj) where T : IRequest { //never gets called } 我的假设是因为Profile来自IRequest然后它应该工作??? […]

MVVM Light Toolkit – Messenger使用Event Aggregator或Mediator Pattern?

有人可以帮我解决一下,如果来自MVVM light toolkit的 I / Messenger类(和实现)演示了Event Aggregator Pattern或Mediator Pattern的使用吗? 如果某人建议它部分地遵循这两种模式,那么我要求详细说明哪个部分的实现类似于保持答案有效的模式。 参考:两种模式之间的比较 ,这是绝对有趣的。

试图了解事件聚合器模式

我试图以一种简单的方式实现事件聚合器模式,逐步学习它。 但我没有找到任何书或很好的video教程谈论它的实现。 我刚刚发现了一些很好的文章,例如http://weblogs.asp.net/rashid/archive/2009/03/05/use-event-aggregator-to-make-your-application-more-extensible.aspx和http ://martinfowler.com/eaaDev/EventAggregator.html第一篇文章太大,让我不了解模式,第二篇文章没有完成:)。 顺便说一句,我创建了我的课程: public class Member { public int ID { get; set; } public string UserName { get; set; } } public class MemberService { public void CommentSubmited() { // increase member score and do some other logic. } } public class Comment { public int ID { get; set; } public […]