Passing data between modules

Topics: Prism v4 - Silverlight 4
May 6, 2011 at 11:33 AM


Say for arguments sake i had 2 modules 'Customer' and 'CustomerOrders'.  When my app starts up the user can display a list of customers, when a customer is selected you can click  an orders button that will load the view dispalying orders for that customer.

From my understanding i can use the eventaggregator to publish the selected customer and in the Ctor of the customer orders view subscribe to this event and then load orders for that customer.  Am i correct in my assumption?

What will happen if i leave this first customer and customer order details  open and then go ahead and open a second customer therefore publishing a different customer object to the eventaggregator, is this going to have any effect on the first customer and customer order details?

Is this even the right way to deal with this secenario?  Are there any blog posts/examples of this secenario that somebody can point me to?



May 6, 2011 at 2:59 PM
Edited May 6, 2011 at 2:59 PM

Hi Paul,

The scenario you're mentioning will behave differently depending on the event aggregator subscription you've used. By default, if you subscribe to an event from your first view and you don't unsubscribe from it, the second time an event is published, it will be handled in both the old and the new view. However, if you, for example, specify a filter in your subscription, you could have the event handled only if a certain condition is met (for example, a field behaving like an ID in your view).

One possible approach that I would recommend for fulfilling this requirement would be to place the responsibility of subscribing to that event in a controller, which would be responsible for holding a list of open views (for example, subscribing to the region's Views collection's CollectionChanged event) and creating new views if applicable (passing the selected customer as a constructor parameter). This could also be implemented using Navigation; if your view implements INavigationAware, you could make the IsNavigationTarget method return false when there is a view with the same customer already opened.

You might find the following resources useful to dig deeper on the aforementioned concepts:

I hope you find this helpful.

Guido Leandro Maliandi

May 9, 2011 at 9:21 AM

Thanks Guido, I'll have a look at the links provided.