メニュー項目をクリックするとEventAggregatorを使用してイベントを公開するMenuコントロールを使用して、アプリケーションを介したナビゲーションを実装しました。以下のようなもの、
this.eventAggregator.GetEvent<ViewRequestedEvent>()
.Publish(new BusinessObject.Model.MenuModel
{
Module = "Dashboard",
PresenterClass = "DashboardViewModel"
});
私のアプリケーションのほとんどのモジュールは、このイベントのサブスクライバーです。フィルタを使用して、モジュールに関連するイベントのみをサブスクライブします
this.eventAggregator.GetEvent<ViewRequestedEvent>()
.Subscribe(LoadViewRequest, ThreadOption.UIThread, true, i => i.Module == "Dashboard");
ビューのリクエストは次のように処理されます。
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) { }
}
この実装をどのように評価しますか?あなたがそれが悪いと思うなら、私がそれを改善するのを手伝うか、より良い代替案を提案してください。