我正在尝试为Prism创建LightInject引导程序,我已经复制了NinjectBootstrapper
(source)的代码并替换了Ninject的{{1}使用LightInject' s IKernel
。我还创建并注册了IServiceContainer
(Ninject version)。
注册和服务定位器适配器正在运行。我看到从服务定位器成功检索到类LightInjectServiceLocatorAdapter
。
在引导程序的RegionAdapterMappings
步骤中,从服务定位器请求类ConfigureRegionAdapterMappings
的实例。这失败了。该课程从未注册过。我无法在SelectorRegionAdapter
中找到对它的任何引用。那么这个类是如何被Ninject引导程序检索的呢?
我已经尝试手动注册该类(还有一些区域适配器和NinjectBootstrapper
)但是Prism失败了DelayedRegionCreationBehavior
UpdateRegionsException
我无法找到任何有关创建添加自己的DI容器的来源,我不知道我错过了哪一步。我做错了什么?
我像这样配置我的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.
(Ninject等价物是ServiceContainer
方法。)
ConfigureKernel
答案 0 :(得分:0)
事实证明我做错了两件事。
对于 npm i xmlhttprequest
中的注册,Ninject引导程序使用扩展方法ConfigureServiceContainer
来注册单例范围内的一些依赖项。
另一件我不明白的事情是,即使没有注册,Ninject也会很乐意解决任何具体类型。 LightInject没有。我终于通过注册Prism.WPF的所有具体类来解决这个问题,这些类以“行为”或“适配器”结束,就像这样:
public static void RegisterTypeIfMissing<A, B>(this IServiceContainer container, bool singletonScope)
最后,我不得不抛弃Prism的所有模块管理。 LightInject期望从// Register all concrete adapters and behaviors in the Prism.WPF assembly
var wpfAssembly = typeof (SelectorRegionAdapter).Assembly;
this.ServiceContainer.RegisterAssembly(wpfAssembly, (t0, t1) => t0.Name.EndsWith("Adapter") || t0.Name.EndsWith("Behavior"));
扩展的单个类出现在程序集中,并且会从那里愉快地加载类型。这适用于我的方法:)。