views:

288

answers:

1

I've implemented navigation through my application using a Menu control which publish an event using EventAggregator on click of menu item. Something like as shown below,

this.eventAggregator.GetEvent<ViewRequestedEvent>()
                    .Publish(new BusinessObject.Model.MenuModel
                    {
                        Module = "Dashboard",
                        PresenterClass = "DashboardViewModel"
                    });

Most of the Modules in my application are subscriber to this event. They use a filter to subscribe only those events relevant to the Module

this.eventAggregator.GetEvent<ViewRequestedEvent>()
            .Subscribe(LoadViewRequest, ThreadOption.UIThread, true, i => i.Module == "Dashboard");

Request for View is handled like this:

private void LoadRequestedView(MenuModel menuItem)
{
    try
    {
        IDashboardViewModel viewModel = this.container.Resolve(Type.GetType(menuItem.PresenterClass)) as IDashboardViewModel;
        this.regionManager.Regions["ViewRegion"].Add(viewModel.View);
        this.regionManager.Regions["ViewRegion"].Activate(viewModel.View);
        this.eventAggregator.GetEvent<ViewNotificationEvent>().Publish(menuItem.Description);
    }
    catch (ResolutionFailedException) { }
}

How do you rate this implementation? If you think it sucks, help me to improve it or suggest a better alternative.

A: 

I think you have a certain lack for separation of concerns with this model. I generally try to keep presentation to the Shell. See this question for how I wold implement this. It simplifies things and abstracts the idea of a RegionManager away from the Modules:

http://stackoverflow.com/questions/1671526/integrating-modules-with-application-in-prism-aka-compositewpf/1676837#1676837

Anderson Imes