更新时间:2023-02-26 22:01:24
您没有您定位的初始化代码。
You lack the initialization code of your locator.
无论你使用棱镜(你呢?),你需要正确设置你的引导程序 - http://msdn.microsoft.com/en-us /library/gg430868(PandP.40).aspx
Either you use Prism (do you?) and you need to set up your bootstrapper correctly - http://msdn.microsoft.com/en-us/library/gg430868(PandP.40).aspx
或者你不使用棱镜,你刚才设置的手动定位器(在主
为例):
Or you don't use Prism and you just set up the locator manually (in Main
for example):
IUnityContainer container = new UnityContainer();
// register the singleton of your event aggregator
container.RegisterType<IEventAggregator, EventAggregator>( new ContainerControlledLifetimeManager() );
ServiceLocator.SetLocatorProvider( () => container );
那么你就可以在你的代码
then you can call in any place of your code
var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
编辑:您编辑你的问题,你现在提棱镜。然后您应该创建一个自定义的引导程序,注册类型和运行引导程序
you have edited your question and you now mention Prism. You should then create a custom bootstrapper, register your types and run the bootstrapper.
public class CustomBootstrapper : UnityBootstrapper
{
}
和呼叫
var bootstrapper = new CustomBootstrapper();
bootstrapper.Run();
在应用程序的启动程序。从我记得, UnityBootstrapper
注册 IEventAggregator
为单身,所以你不必重复。
in the starting routine of your application. From what I remember, UnityBootstrapper
registers the IEventAggregator
as singleton so you don't have to repeat that.