0
votes

I am trying to replace the built in IOC container in Catel with SimpleInjector.

From their prism example (i am using catel+prism) the bootstrapper claims to be configuring Unity in the following fragment:

/// <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>();
}

However I don't see how this configures the IUnityContainer and according to my debugger, it does not in fact configure unity (the Container being used is the built in ServiceLocator of Catel). Can someone more familiar with Catel help me figure out how to do this? I would be happy to write it up for the documentation.

2

2 Answers

0
votes

Here is my solution for Catel 3.8 and Autofac. Should work for different 3rd party container as well.

https://stackoverflow.com/a/20458474

0
votes

The documentation (xml docs) is probably outdated because it doesn't use IUnityContainer. In fact it uses the IServiceLocator in Catel.

The best way to replace the IServiceLocator with your own implementation is to inject it in the constructor (BootstrapperBase). I will also add the same constructor overrides to the other bootstrappers (with the TShell and TShell, TModuleCatalog)

Another option is to replace the IoCConfiguration.DefaultServiceLocator. The bootstrapper will fall back on that one if no service locator is specified.