Container and VM

Topics: Prism v4 - WPF 4
Aug 22, 2010 at 10:35 AM
Edited Aug 23, 2010 at 2:37 PM


I'm newbie under PRISM 4. I block on problem. In a simple MVVM applicaton with no modules. With one Shell, two User control.

My problem is i want to use aggregator between this two user controls. How can I do to send unity container at two VM but I want to keep "blendability" ?

Thanxs a lot for your help.


Nobody for help me ?


Aug 27, 2010 at 8:16 PM


If the usercontrols reside in two different modules, event aggregator could be the appropriated approach to communicate these two components, though in your scenario you could use regular .Net events.

Therefore, if you need to use Event Aggregator in your application, you could take a look at the following documentation section on MSDN. Take into account these links assume that the application has a bootstrapper that properly configures the event aggregator. Your scenario if you are only using MVVM (e.g. MVVM RI or MVVM Quickstart) you might not have this bootstrapper in place:

There is no guidance for blendability using DI containers, so far. Regarding to blendability you could check the following document in the Prism4.chm of the latest drop:

  • Achieving Blendability (new)

Not taking into account blendability you could could check the MVVM RI, which use MEF as the composition container.

Please let me know if this helps.

Fernando Antivero

Sep 20, 2010 at 3:58 PM


Sorry for my late answer.

I read various articles that you gave me in the comment.

I find a solution but i don't know if it respect MVVM design pattern.

My solution : I have a static class in where i have a static property where i put a instance of container.

In the ConfigureContainer bootstrapper, I update this property.

I use in my differents viewmodels. About my blendability, in the modelview ctor, i test if i was in indesignmodel or not. And if I not in design a call the container throught my 'infrastructure' property.

What do you find about this approach ?

Thanxs a lot for your help.



Sep 20, 2010 at 9:34 PM


If you are using Unity, you could use DI to retrieve your container from everywhere (ViewModel) using Constructor Injection, Dependency Property, etc. You could see this in the following pseudo-code:

public class VM
      ctor (IUnityContainer container)
             //your code here

Regarding to your approach, it seems that has not issues with MVVM pattern, but that approach is not use in the Quickstarts or Reference Implementation in Prism. 

The team is actually working on this, as you can check in today's drop 8 of Prism, since the document for achieving blendability and the MVVM RI have been updated with a new approach. So I would suggest to you to take a look at this new drop (you could download the lasted version here).

Fernando Antivero

Sep 21, 2010 at 8:05 AM


but if i use this approach I lost the blendability because blend not found a default ctor.

I download and look the Drop 8 of PRISM.

Thanxs for your help