【发布时间】:2012-08-01 18:36:50
【问题描述】:
我开始使用 Prism 和 MVVM 处理 WPF 项目,我正在尝试使用 eventAggregator,但是当执行下面的行时会引发异常:
IServiceLocator ob = ServiceLocator.Current; // This line causes a Null pointer exception
EventAggregator = ob.GetInstance<IEventAggregator>();
但我无法理解我做错了什么,也许这是一件非常简单的事情,但我已经为此苦苦挣扎了几个小时。
希望有人能帮助我,在此先感谢
【问题讨论】:
-
这段代码在哪里执行,你使用的是哪个引导程序?例如,如果是 Unity,您可能应该使用
IUnityContainer而不是ServiceLocator来解析实例。 -
我没有使用任何引导程序,但感谢 Wiktor Zychla 我解决了我的问题
标签: c# wpf prism eventaggregator