【发布时间】:2011-11-07 14:31:42
【问题描述】:
在我们的 prism 应用程序中,当用户单击树中的一个项目(单独的模块)时,我们需要将一个模块加载到中心窗格。如果给定路径,中心窗格中的模块(例如设计器模块)可以打开文件并显示自身。如何将文件的路径传递给这个模块? 例如
在设计器模块中
public DesignerViewModel(DataAccess dataAccess)// This will be injected
{
}
//The following class can create the model objects using the IDataService for getting data from remote location
public DataAccess(IDataService service)//this will be injected
{
}
数据访问对象是 Designer 模块的本地对象,所以我不想将它暴露给模块外部。所以注册是在模块中完成的
public class DesignerModule : IModule
{
public void Initialize()
{
var container = ServiceLocator.Current.GetInstance<IUnityContainer>();
container.RegisterType<Object, DesignerView>("DesignerUI");
container.RegisterType<DataAccess>();
}
}
IDataService在应用层注册
public class BootStrapper : UnityBootstrapper
{
protected override void ConfigureContainer()
{
base.ConfigureContainer();
Container.RegisterType<IDataService, DataService>();
}
}
请注意,IDataService 是整个应用程序的单例。我无法传递特定于 IDataService 中模块实例的文件路径。请注意,您可以根据需要在中心窗格中打开任意数量的模块,只需单击树项->树将触发具有选定项 id 的事件->应用程序将找到与项 id 对应的路径并调用模块。
当我说 _regionManager.AddToRegion("CenterRegion", DesignerModule); 时我将如何传递路径Prism 会把所有的依赖注入都做的很好,但是如何通过路径是个大问题?
【问题讨论】:
标签: c# unity-container prism