与 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
{
}
数据访问对象是设计器模块本地的,因此我不想将其公开到模块外部。所以注册是在模块中完成的
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 会漂亮地完成所有的依赖注入,但是如何传递路径是一个大问题?
In our prism application we need to load a module to the centre pane when the user clicks an item in a tree(seperate module). The module in the centre pane(say designer module) can open a file and display itself if it is given a path. How can I pass the path of the file to this module?
For example
in Designer module
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
{
}
The data access object is local to the Designer module, so I wouldnt like to expose it to outside the module. So the registration is done in the module
public class DesignerModule : IModule
{
public void Initialize()
{
var container = ServiceLocator.Current.GetInstance<IUnityContainer>();
container.RegisterType<Object, DesignerView>("DesignerUI");
container.RegisterType<DataAccess>();
}
}
IDataService is registered in the application level
public class BootStrapper : UnityBootstrapper
{
protected override void ConfigureContainer()
{
base.ConfigureContainer();
Container.RegisterType<IDataService, DataService>();
}
}
Note that IDataService is a singleton for the entire app. I cannot pass the path of file which is specific to a module instance in IDataService. Note that you can open any number of modules in the centre pane as you like, just click on a tree item->tree will fire an event with the selected item id->app will find out a path corresponding to the item id and invoke the module.
How will I pass the path when I say _regionManager.AddToRegion("CenterRegion", DesignerModule); Prism will do all the dependency injections beautifully, but how to pass the path is a big question?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 EventAggregator 与模块之间的消息。
每个模块都订阅EventAggregator。
当您打开模块时,您可以向主机控制发送有关新生儿的通知。
主机控制发送回带有初始化数据的响应。
You can use EventAggregator to exchange with messages beetwen modules.
Each module subscribe to EventAggregator.
While you open a module you can send to host control notification about newborn.
Host control send response back with initialization data.
我从同事那里找到了答案。当你调用Resolve()时,参数可以用你自己的对象覆盖。因此,创建要注入的对象,填充它并通过 Resolve<>() 和 ParameterOverride 传递。在 google 中搜索 ParameterOverride 了解更多信息。
I found out the answer from my colleague.The parameters can be overriden with your own objects when you call Resolve(). So create the object which is going to be injected, populate it and pass with the Resolve<>() with ParameterOverride. Search for ParameterOverride in google for more information.