0

我正在尝试用 SimpleInjector 替换 Catel 中内置的 IOC 容器。

从他们的 prism 示例(我使用的是 catel+prism)中,引导程序声称在以下片段中配置 Unity:

/// <summary>
/// Configures the <see cref="IUnityContainer"/>. May be overwritten in a derived class to add specific
/// type mappings required by the application.
/// </summary>
protected override void ConfigureContainer()
{
    base.ConfigureContainer();

    Container.CanResolveNonAbstractTypesWithoutRegistration = true;

    Container.RegisterType<IDepartmentRepository, DepartmentRepository>();
    Container.RegisterType<IEmployeeRepository, EmployeeRepository>();
}

但是我看不出这是如何配置 IUnityContainer 的,根据我的调试器,它实际上并没有配置统一(正在使用的容器是 Catel 的内置 ServiceLocator)。更熟悉 Catel 的人可以帮我弄清楚如何做到这一点吗?我很乐意为文档编写它。

4

2 回答 2

0

文档(xml 文档)可能已过时,因为它不使用 IUnityContainer。事实上,它使用 Catel 中的 IServiceLocator。

用您自己的实现替换 IServiceLocator 的最佳方法是将其注入构造函数 (BootstrapperBase)。我还将向其他引导程序添加相同的构造函数覆盖(使用 TShell 和 TShell,TModuleCatalog)

另一种选择是替换 IoCConfiguration.DefaultServiceLocator。如果没有指定服务定位器,引导程序将退回到那个。

于 2013-10-24T07:06:01.440 回答
0

这是我对 Catel 3.8 和 Autofac 的解决方案。也应该适用于不同的 3rd 方容器。

https://stackoverflow.com/a/20458474

于 2013-12-09T08:43:26.077 回答