views:

398

answers:

2

I've got a WPF application which uses the MVVM pattern throughout, no code-behind, the ViewModels communicate with each other through the MainViewModel which gets injected into each of them.

Eventually, this application needs to be incorporated into an application which uses Composite Application Library, Unity, etc. Looking through the code and documentation of CAL, I can see how I can register my whole application as a module in the CAL application, but how is my application-as-module going to communicate with the other modules that are also dynamically loaded? I'm expecting, e.g. that each module gets the CAL application somehow injected, or that there is some kind of Event Controller or Messenger with which I can loosely communicate with the other modules, i.e. can send a message and respond to events but not worry if those modules are actually there or not.

How do Composite Application modules communicate with each other?

A: 

Check out Prism's event aggregator.

HTH, Kent

Kent Boogaart
+2  A: 

If you are using CAL(Prism) look into the Event Aggregator/CompositePresentationEvent where it uses the Publisher/Subscriber pattern (aka Pub/Sub) so some Modules of the app is subscribed to an Event Aggregator, so when another Module has changes it will Publish changes e.g.(SelectedItemChanged) to the Event Aggregator, If Other Modules are interested in the changes Published they will act within there part of the application.

Example:

A Desktop e-mail Application:

Modules:

  • Mail Items (MailID,Subject,Sender,SentDate..etc)
  • Detail View (MessageBody)

If the selection in the Mail Items ListBox gets changed,It publishes the MailID to the Event Aggregator then Detail View knows about the change and then it grabs the MessageBody for that E-mail by MailID. where "MailItems" and "DetaliView" Modules have been developed by different teams but they have MailID as a common expected message in between.

Abu S3ood