我正在尝试为 Prism 创建一个 LightInject 引导程序,我复制了NinjectBootstrapper
( source ) 的代码并将 Ninject 替换IKernel
为 LightInject IServiceContainer
。我还创建并注册了一个LightInjectServiceLocatorAdapter
(Ninject 版本)。
注册和服务定位器适配器正在工作。我看到该类RegionAdapterMappings
已从服务定位器中成功检索。
在引导程序的步骤中,从服务定位器请求ConfigureRegionAdapterMappings
一个类的实例。SelectorRegionAdapter
这失败了。该课程从未注册过。我在NinjectBootstrapper
. 那么 Ninject 引导程序是如何检索这个类的呢?
我已经尝试手动注册该类(以及更多的区域适配器和DelayedRegionCreationBehavior
),但随后 Prism 失败并出现UpdateRegionsException
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Prism.Regions.Behaviors.RegionCreationException: An exception occurred while creating a region with name 'Menu'. The exception was: System.Collections.Generic.KeyNotFoundException: The IRegionAdapter for the type System.Windows.Controls.ContentControl is not registered in the region adapter mappings. You can register an IRegionAdapter for this control by overriding the ConfigureRegionAdapterMappings method in the bootstrapper.
我找不到任何处理创建添加自己的 DI 容器的来源,我不知道我错过了哪一步。我究竟做错了什么?
我ServiceContainer
像这样配置我的(Ninject 等价的ConfigureKernel
方法)。
protected virtual void ConfigureServiceContainer()
{
this.ServiceContainer.RegisterInstance<IServiceContainer>(this.ServiceContainer);
this.ServiceContainer.RegisterInstance(this.Logger);
this.ServiceContainer.RegisterInstance(this.ModuleCatalog);
if (!this.useDefaultConfiguration)
return;
this.ServiceContainer.Register<IServiceLocator, LightInjectServiceLocatorAdapter>();
this.ServiceContainer.Register<IModuleInitializer, ModuleInitializer>();
this.ServiceContainer.Register<IModuleManager, ModuleManager>();
this.ServiceContainer.Register<RegionAdapterMappings, RegionAdapterMappings>();
// The following 4 registrations are not in the NinjectBootstrapper
this.ServiceContainer.Register<SelectorRegionAdapter, SelectorRegionAdapter>();
this.ServiceContainer.Register<ItemsControlRegionAdapter, ItemsControlRegionAdapter>();
this.ServiceContainer.Register<ContentControlRegionAdapter, ContentControlRegionAdapter>();
this.ServiceContainer.Register<DelayedRegionCreationBehavior, DelayedRegionCreationBehavior>();
this.ServiceContainer.Register<IRegionManager, RegionManager>();
this.ServiceContainer.Register<IEventAggregator, EventAggregator>();
this.ServiceContainer.Register<IRegionViewRegistry, RegionViewRegistry>();
this.ServiceContainer.Register<IRegionBehaviorFactory, RegionBehaviorFactory>();
this.ServiceContainer.Register<IRegionNavigationJournalEntry, RegionNavigationJournalEntry>();
this.ServiceContainer.Register<IRegionNavigationJournal, RegionNavigationJournal>();
this.ServiceContainer.Register<IRegionNavigationService, RegionNavigationService>();
this.ServiceContainer.Register<IRegionNavigationContentLoader, RegionNavigationContentLoader>();
}