每次使用 Prism 请求模块时,我都需要运行一个函数

发布于 2024-08-19 04:28:49 字数 167 浏览 2 评论 0原文

我在应用程序中使用 Prism,并且我需要一种在每次请求模块时运行调用函数的方法。问题是,这个函数将查询数据库中的某些项目,每次通过按菜单中的模块项目按钮请求模块时,我都需要执行此操作。我尝试将其添加到构造函数中,但问题是在从引导程序初始化应用程序期间调用构造函数!

有没有一种简单的方法可以做到这一点?

I am using Prism in an application and I need a way to run call a function every time a module is requested. The thing is that this function will query the database for some items, and I need to do this every time the module is requested by pressing the module item buttom from a menu. I tried adding this to the constructor, but the problem is that the constructor is called during the initialization of the application from the bootstrap!

Is there a simple way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天涯沦落人 2024-08-26 04:28:49

您如何请求您的模块?一种方法是使用 EventAggregation,并让模块监听具体事件将告诉他们他们被要求。如果您使用 EventAggregation 来请求模块,您将拥有一个处理请求事件的事件处理程序。希望您也应该能够使用事件处理程序来调用您的函数。

How are you requesting your module? One way to do this is to use EventAggregation, and have the modules listen for specific events which will tell them they are requested. If you use EventAggregation to request you modules you will have an event handler that handles the request event. Hopefully you should be able to use your event handler to call your function too.

七七 2024-08-26 04:28:49

我非常确定每次加载模块时都会调用 Initialize 函数。您只需将代码放在那里即可。

I'm pretty sure that the Initialize function is called each time the module is loaded. You can just put code in there.

行雁书 2024-08-26 04:28:49

当使用 Unity 作为 IoC 容器,并且您使用 Unity 请求模块时,也许可以通过创建自己的 Unity 拦截器(Microsoft.Practices.Unity.Interception 命名空间)来工作

when using unity as IoC container, and you request the module using unity, maybe this could work by creating your own unity interceptor (Microsoft.Practices.Unity.Interception namespace)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文