MEF 程序集加载声明
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
我不完全确定您想要完成什么,但如果您只想在 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.