Prism with WPF - How to register dependencies globally?

Topics: Prism v4 - WPF 4
Jul 22, 2012 at 6:52 PM



I am fairly new to Prism and WPF. I have gone through some topics and observed that each module project is associated with a IOC registration.  But I think it would be better if we can register all the dependencies in a common class globally.

Is there any way to do this?




Jul 23, 2012 at 3:29 PM
Edited Jul 23, 2012 at 3:30 PM


As mentioned in this section of the Prism documentation before using containers there are some considerations that should me made, for example:

Consider whether you want to configure the container through code or configuration:

  • If you want to centrally manage all the different services, configure the container through configuration.
  • If you want to conditionally register specific services, configure the container through code.
  • If you have module-level services, consider configuring the container through code so that those services are registered only if the module is loaded.

Based on this, if what you are looking for is to centralize your registration, I believe this could be achieved for example by overriding the ConfigureContainer method in the Bootstrapper, where a number of core Prism services are registered by default (this is a stage of the initialization process of a Prism application).

You could find more information about this, in the following chapter of the Prism documentation:

Also, another approach could be configuring your container through a configuration file. However, some container such as MEF does not provide this functionality.

I believe, you could find useful information on how to achieve this with Unity in the following resource:

I hope you find this useful,

Agustin Adami