Using Unity as primary IoC container

If you are going for Catel, we always recommend to use the ServiceLocator of Catel as primary IoC container. However, if you want to use Unity as the primary IoC container, follow the instructions below.

This is not a full starting guide to Unity, if you are looking for documentation about Unity, continue searching

Registering the container in Catel

It is required to register the external container in the ServiceLocator of Catel. This is required because all the items that are registered by Catel itself are known in the Unity container. Catel will automatically register all types in the Unity container when the container is registered.To register the container, simple use this call when the container is created:

ServiceLocator.Instance.RegisterExternalContainer(myUnityContainer);

At this point, all the services registered by Catel are now registered in the Unity container.

 Resolving properties

In Unity, it is required to resolve properties like this:

PleaseWaitService = myUnityContainer.Resolve<IPleaseWaitService>();

The code above imports the IPleaseWaitService (which is internally registered by Catel) via Unity.