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.