从 Silverlight 中的 Castle 内核导入 MEF
我目前在我的项目中使用 MEF,但是,遗留组件使用 Castle 导出其所有组件。
除了从 Xap 获取导出之外,我希望在创建新对象时能够从该内核导入。
这可能吗?你能给我看一些示例代码吗?
I'm currently using MEF in my project, however, a legacy component uses Castle to export all its components.
I would like to be able to Import from this kernel when creating new objects, in addition to getting the exports from the Xap.
Is this possible? Can you show me some example code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MEF 被设计得尽可能灵活,其秘密隐藏但真正出色的功能之一是能够定义新的 ExportProvider 实例,允许您插入其他组件。我之前已经通过在带有 MEF 项目的 ASP.NET MVC 中利用 Common Service Locator 项目讨论过这一点(请参阅第 3 部分 此处)。
CSL 是一种非常灵活的方法,因为许多现有的 IoC 容器都有许多特定的 CSL 实现,例如 Castle、Autofac、Ninject、Unity 等。
另一个很好的示例可以在 此处,它演示了一种略有不同但基本相似的方法。
MEF was designed to be as flexible as possible, and one of its secretly hidden but real nice features, is the ability to define new
ExportProvider
instances, that allow you to plug in additional components. I've talked about this previously by utilising the Common Service Locator project in an ASP.NET MVC with MEF Project (see part 3 here).The CSL is a nice flexible approach, as there are many specific CSL implementations for many of the existing IoC containers, such as Castle, Autofac, Ninject, Unity etc.
Another good example can be found here, which demonstrates a slightly different, but fundamentally similar approach.
正如马修正确所说,做到这一点的方法是使用
ExportProvider
另一个例子是 此处(它演示了从 Xaml 的导出)。
以下是我最终为解决问题所做的事情。
As Matthew correctly said, the way to do this is using an
ExportProvider
Another example is here (it demonstrates exports from Xaml).
Below is what I did in the end to solve the problem.