【发布时间】:2018-01-21 01:04:31
【问题描述】:
我是 Prism 的新手,我有一个应用程序,我需要一个自定义区域映射。
当我尝试使用 ServiceLocator 解析 IRegionBehaviorFactory 时,我收到错误:
尝试获取 IRegionBehaviorFactory 类型的实例时发生激活错误,键“”
我知道这是因为 RegionBehaviorFactory 类接收 Microsoft.Practices.Unity.IServiceLocator,但在 Unity 7.0 中我将其用作 ServiceLocator Unity.ServiceLocation.UnityServiceLocator
我该怎么办? 这是我的 bootstrapper.cs
class Bootstrapper : UnityBootstrapper
{
private UnityContainer uc = new UnityContainer();
protected override void ConfigureServiceLocator()
{
base.ConfigureServiceLocator();
UnityServiceLocator locator = new UnityServiceLocator(uc);
ServiceLocator.SetLocatorProvider(() => locator);
}
protected override DependencyObject CreateShell()
{
return ServiceLocator.Current.GetInstance<wMain>();
}
protected override void InitializeShell()
{
Application.Current.MainWindow = (wMain)this.Shell;
Application.Current.MainWindow.Show();
}
protected override IModuleCatalog CreateModuleCatalog()
{
return new ConfigurationModuleCatalog();
}
protected override void InitializeModules()
{
base.InitializeModules();
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
uc.RegisterType<IServiceLocator, UnityServiceLocator>();
uc.RegisterType<IRegionBehaviorFactory, RegionBehaviorFactory>();
Application.Current.Resources.Add("IoC", uc);
}
protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
var mappings = base.ConfigureRegionAdapterMappings();
var aa = ServiceLocator.Current.GetInstance<IRegionBehaviorFactory>();
mappings.RegisterMapping(typeof(RadPaneGroup), new RadPaneGroupRegionAdapter(uc.Resolve<RegionBehaviorFactory>()));
return mappings;
}
}
谢谢
【问题讨论】:
标签: c# wpf unity-container prism