在PRISM WPF应用程序中具有依赖于模块的状态注入 [英] Have a module dependent Injection for State in PRISM WPF application

查看:244
本文介绍了在PRISM WPF应用程序中具有依赖于模块的状态注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个PRISM WPF MVP应用程序,我们希望有一个状态可以在同一模块的视图之间共享数据.由于PRISM默认情况下没有状态,因此我想知道是否有任何方法可以实现此目的.目前,我已经向State注入了Dictionary作为后台存储,但是问题是它的Global即在各个模块中都可用.我真的很想将这种注入的范围指定为模块特定的.

hi we have a PRISM WPF MVP application, we would like to have a state to share data between the views in the same module. Since PRISM by default doesnt have a state, was wondering if there is any way i could implement this. Presently i have injected a State with Dictionary as back-store, but the problem is its Global i.e available across the modules. i would really like to scope this injection being module specific.

我相信统一性允许根据名称将不同的类注册到同一接口,不确定我是否唯一的选择就是在我的场景中利用它.

I believe unity allows registering different classes to the same interface based on name, not sure if the only choice i have is to leverage that for my scenario.

任何帮助都会很棒!谢谢!

Any help would be great! Thanks!

-ioWint

推荐答案

感谢您的更新解决方案.我试图避免基于名称的Unity注册,这会迫使我的演示者知道模块状态注册密钥. 我正在阅读Unity上的stackoverflow帖子,并在此处

thanks for your updated solution. I was trying to avoid a name based Unity registration, which would force my Presenter in knowing the Modules State registration Key. I was reading stackoverflow posts on Unity and found the discussion over here Is it possible to override parameter values when using Method Injection with Unity? .

经过几个小时的尝试和错误,我最终实现了所需的功能.

After couple of hours of trial and errors, i ended up achieving the desired functionality.

我做了什么:

我的模块有一个BaseClass-> BaseModule:IModule我有一个State属性,它符合在Infrastructure.Interface中定义的IStateService.我在BaseModule()构造函数中实例化此State属性. 注意:要使用这种方法,我必须使我的演示者具有公共IStateService状态.属性.

I have a BaseClass for my Modules -> BaseModule:IModule i have a State Property in it which conforms to my IStateService defined in the Infrastructure.Interface. I Instantiate this State property in the BaseModule() constructor. Note: to go with this approach i have to make my Presenter's have a public IStateService State; property..

在模块中注册Presenter时,我正在指定

At the time of registering the Presenter in the module, i am specifying

<UnityContainer>.RegisterType<MyPresenter, new InjectionProperty("State", State).

Am覆盖Presenter中名为"State"的公共属性,并在模块中定义了State实例值. 这样,我就可以将模块状态作为每个View演示者的状态.

Am overriding a public property in Presenter which has name "State" with the State instance value defined in the Module. this way i am able to get the Modules State as the State for each of the View's presenter.

感谢大家指导我寻求解决方案.

Thanks guys for directing me towards a solution.

-ioWint

这篇关于在PRISM WPF应用程序中具有依赖于模块的状态注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆