Module Constructor Behavior

Topics: Prism v2 - Silverlight 2, Prism v2 - WPF 3.5
Apr 6, 2009 at 10:13 PM
I see in the examples that there are several ways that you are supporting construction (not Initialization) of Modules but I can't see it documented anywhere. Any clues to how you are calling constructors by convention?  What are all the Interfaces you support?
Apr 7, 2009 at 8:52 PM



The reason why this happens is because classes that implement IModule interface are not meant to be instanced as objects usually are (using the new keyword) but using the Unity container instead.

When a class gets resolved through the Unity container, it is injected with the different dependencies it has declared. This dependencies have to be previously registered in the container and if not a new object of that type is created. To better understand this behavior you might find useful the Dependency Injection pattern and the Container design concept in the documentation.  


For example:


public class ModuleA : IModule


      private IRegionManager manager;


      public ModuleA(IRegionManager regionManager)


// regionManager is injected into this class. It is the instance that was registered for the IRegionManager interface in the container

      this.manager = manager;



public void Initialize()


//Some logic




The interfaces used are usually abstractions of different elements from the Composite Application Guidance for WPF & Silverlight. Example: IRegionManager is implemented by the RegionManager class, IEventAggregator is implemented by the EventAggregator class. This abstractions allow a more decoupled application, since the code is not dependant on the implementation.


For more information you could download and go over the Unity Application Block documentation and source code here. P&P has recently released Hands-on Labs for Unity 1.2 which cover Dependency Injection with Unity among other topics.


Please let me know if this helps.


Damian Schenkelman
Apr 7, 2009 at 8:56 PM
This was me missing the barn because I was looking at the woodgrain. Of course its using Constructor injection so we're all good.