Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modules in Prism (CAL) communicate with each other?

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?

like image 730
Edward Tanguay Avatar asked Jul 01 '09 11:07

Edward Tanguay


People also ask

What is a module in Prism?

Yes, a module in Prism is simply a loosely coupled functional unit in form of a class library project that typically represents a set of related concerns and includes a collection of related components, such views, view models, models and other classes.

What is Prism unity?

Prism is a framework for building loosely coupled, maintainable, and testable XAML applications in WPF, and Xamarin Forms. Separate releases are available for each platform and those will be developed on independent timelines.

Why do we need prism in WPF?

Prism helps to create flexible applications by allowing them to be more easily updated as new capabilities are developed and integrated. Prism also allows WPF applications to be developed using common services and components, allowing the application to be deployed and consumed in the most appropriate way.

What is Prism framework in WPF?

Prism is a Microsoft framework which assists you to design and build rich, flexible, and easy-to-maintain complex applications specific to Windows Presentation Foundation (WPF) desktop applications, Silverlight Rich Internet Applications (RIAs), and Windows Phone applications.


2 Answers

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.

like image 128
Abu S3ood Avatar answered Oct 05 '22 04:10

Abu S3ood


Check out Prism's event aggregator.

like image 24
Kent Boogaart Avatar answered Oct 05 '22 04:10

Kent Boogaart