MEF 程序集加载声明

发布于 2024-10-31 18:18:14 字数 275 浏览 5 评论 0原文

在 Prism 中,我能够从动态加载的程序集中声明我期望加载程序集如何以及何时初始化我。也就是说,我可以放置以下类属性:

[ModuleExport(typeof(MyModule), InitializationMode = InitializationMode.WhenAvailable)]

这将导致我的模块在加载时被初始化。

我一直在寻找用 MEF 做同样事情的能力,但我还不是很熟悉它。我尝试在 MSDN 和文档上搜索,但没有看到太多内容。

预先感谢您的帮助!

In Prism, I have the ability to declare from my dynamically loaded assembly how I expect the loading assembly to initialize me and when. That is, I could place the following class attribute:

[ModuleExport(typeof(MyModule), InitializationMode = InitializationMode.WhenAvailable)]

Which would cause my module to be initialized as it's loaded.

I was looking for the ability to do the same with MEF, but I am not very familiar with it yet. I tried searching around on MSDN and the documentation, but I didn't see much.

Thanks in advance for your help!

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

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

发布评论

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

评论(2

花开雨落又逢春i 2024-11-07 18:18:14

MEF 没有内置类似的功能。在 Prism 中,InitializationMode 是导出上的元数据,相应的导入器会查看并遵循该元数据。因此,如果需要,您可以在应用程序中使用相同类型的约定。

MEF doesn't have anything like this built in. In Prism, the InitializationMode is metadata on the export, that the corresponding importer looks at and follows. So you could use the same kind of convention in your application if you need it.

红墙和绿瓦 2024-11-07 18:18:14

我不完全确定您想要完成什么,但如果您只想在 MEF 完成初始化时做一些工作,那么您可以实施 IPartImportsSatsifiedNotification 并在完成满足您的导入时获取回调。

I'm not entirely sure what you are trying to accomplish but if you just want to do some work when MEF is finished initializing you then you can implement IPartImportsSatsifiedNotification and get a callback when it finishes satisfying your imports.

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