When to Use Composite Command vs Event aggregator

Topics: Prism v1, Prism v2 - WPF 3.5
Aug 11, 2009 at 11:07 AM

I have a shell with one region. This region is loaded with the help of Module. Now within this shell, I have 4 regions.My goal is to communicate between these 4 regions in a module.I am currently using Event aggregators to communicate between the regions in a module.However, the performance of the application is very slow. After some goggling I came to know that event aggregator should be used to communicate between modules and not within modules.

Now the questions I have is

 1. Is it better to use multiple regions within a single module or should I have only one region within a module

    If I use multiple regions, then communication between regions (or their presentation model) becomes a challenge.

   If I use a single region, then I am worried about the future changes and coupling. 

2. What is the best way to communicate between regions in a module? Each of my regions has their own presentation models. My goal is to communicate between the presentations models (of the views or regions) within a module in prism.   Can I use composite WPF commands for the same or should I use event aggregator.



Aug 11, 2009 at 11:43 AM
Edited Aug 11, 2009 at 11:56 AM

Hi devgeekrai,

A shared presentation model (aka View Model) would be an efficient method.   I have a CALDemo (AVAILABLE ON THIS BLOG) application that demonstrates how this can be done using a combination of the Model-View-Presenter and Model-View-ViewModel patterns.   The MyControlPresenter shows the minimal code required to wire-up the MVP-MVVM model (see example below).   The Smart Client Software Factory folks will recognize the pattern as well as virtual methods - the remaining concepts came from PRISM V2 Drop 7 (top down composition quickstart).

Each view updates the model as applicable and if required there is a hook OnModelPropertySet() which will allow a view to be notified when model properties change.   If you have all of your views within a module share the same Presentation Model you simply have to update the model and your work is done.  Since each View (MVP-MVVM) is encapsulated I use the event aggregator for publishing information that would not be appropriate on a domain model but is of value to external processes - for example generating Status bar messages and/or calculations that are composed of a combination of internal information as well as model information.

    public class MyControlPresenter : PresenterBase<IMyControl>
        private IEntityDataService entityService;
        private IMyControlPresentationModel model;

        public MyControlPresenter(
            IMyControl view, IUnityContainer container, 
            IMyControlPresentationModel model,
            IEntityDataService entityService) 
                : base(view, container, model)
            this.entityService = entityService;
            this.model = model;
        protected override void OnProcessEvent(ProcessEventArgs e)

        protected override void OnModelPropertySet(string propertyName)

        protected override void OnViewSet()