经过几个小时的阅读棱镜相关的文章和论坛我碰到了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