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
pattern and the
Container design concept in the documentation.
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()
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.