經過幾個小時的閱讀棱鏡相關的文章和論壇我碰到了Erwin van der Valk的博客 - How to Build an Outlook Style Application的文章「如何構建一個Outlook風格的應用程序」。
在架構的一部分中,使用了一個Unity子容器來解析類型實例。這正是我第二個問題的答案所需要的:我需要「範圍」(通過窗口)依賴注入(例如:窗口範圍的EventAggregator,地圖控件等)
以下是我如何創建一個新窗口:
private IShellWindow CreateNewShell(IRegionManager regionManager)
{
IUnityContainer childContainer = this.Container.CreateChildContainer();
... register types in child container ...
var window = new ShellWindow();
RegionManager.SetRegionManager(window, regionManager);
window.Content = childContainer.Resolve<MapDocumentView>();
return window;
}
因此,MapDocumentView及其所有組件都將被注入(如果需要)窗口範圍的實例。
既然我可以有範圍的注入對象,我可以在基於模塊的MapPresenter中獲取窗口範圍的地圖。爲了回答我的第一個問題,我定義了一個由具有MapPresenterRegistry屬性的Bootstrapper實現的接口IHostApplication。該界面被添加到主容器。
初始化後,模塊將註冊他們的演示者,並在創建窗口時,它們將被實例化。
所以對於模塊初始化:
public void Initialize()
{
...
this.hostApplication.MapPresenterRegistry.Add(typeof(ModuleSpecificMapPresenter));
...
}
初始化地圖窗口中的代碼:
private void View_Loaded(object sender, RoutedEventArgs e)
{
// Register map in the == scoped container ==
container.RegisterInstance<IMap>(this.View.Map);
// Create map presenters
var hostApplication = this.container.Resolve<IHostApplication>();
foreach (var mapPresenterType in hostApplication.MapPresenterRegistry)
{
var mapPresenter = this.container.Resolve(mapPresenterType) as IMapPresenter;
if (mapPresenter != null)
{
this.mapPresenters.Add(mapPresenter);
}
}
}
與特定模塊MapPresenter:
public ModuleSpecificMapPresenter(IEventAggregator eventAggregator, IMap map)
{
this.eventAggregator = eventAggregator;
this.map = map;
this.eventAggregator.GetEvent<AWindowSpecificEvent>().Subscribe(this.WindowSpecificEventFired);
// Do stuff on with the map
}
因此,這些都是大我的解決方案的線。我不太喜歡的是我沒有這樣利用區域管理。我幾乎有自定義代碼來完成這項工作。
如果您有任何進一步的想法,我會很高興聽到他們。 Eduard
每個引腳都有獨立的模塊?不,男人,這不酷。模塊必須根據其功能而有所不同,但在這種特殊情況下,最好使用包含子視圖模型集合的視圖模型。接下來,第二個問題提供一些信息,顯示在自定義窗口中以及它們如何打開。我認爲有必要將引用存儲在全局對象中,但我不知道所有的細節,所以我現在還不能確切地說。 – vorrtex 2011-05-10 21:16:27
不,不是每個引腳的模塊:)模塊應該註冊一個類(演示者),它將以某種方式被實例化並賦予Shell的地圖控件。然後它可以例如顯示城市中所有攝像頭的圖標。另一個模塊可以使用相同的地圖來顯示交通信息。這就是爲什麼這些模塊是獨特的,但應該與相同的「文檔 - 全球」地圖控制交互。 – Eduard 2011-05-10 22:29:44
自定義窗口與打開新的Word文檔基本相同,但在我的情況下,它將是一個「地圖文檔」。基本上是初始shell的精確副本。因此,在一個窗口中,您可以啓用流量,並在另一個窗口中啓用相機信息(例如)。關於「他們是如何被打開的」,我正在考慮沿着「文件 - >新文檔」的方式。 – Eduard 2011-05-10 22:33:47