简体   繁体   English

WPF MEF和第三方库

[英]WPF MEF and 3rd party library

I have 3rd party dll and in this dll is such hierarchy: class Node realize interface INode. 我有第三方DLL并且在这个dll中是这样的层次结构:类Node实现接口INode。 This dll uses Ninject binding in it. 该dll在其中使用Ninject绑定。 My application uses this dll and Prism and MEF as IoC container. 我的应用程序使用此dll以及Prism和MEF作为IoC容器。 I haven't practice in Prism and MEF before, so one thing I want to do is to bind INode to Node. 我以前没有在Prism和MEF中练习,所以我想做的一件事就是将INode绑定到Node。 I don't have access to INode and Node, so write smth like that I can't: 我没有访问INode和Node的权限,所以不能这样写:

[Export(typeof(INode))]
class Node : INode{...}

In Ninject I would did it in such way: 在Ninject中,我会这样进行:

Bind<INode>().To<Node>();

Can I do something like that in MEF? 我可以在MEF中做类似的事情吗? Thnx. 日Thnx。

Have a look at MEF's Convention Model . 看看MEF的会议模型 You can use it for exporting types you don't control. 您可以将它用于导出您无法控制的类型。 For example: 例如:

var registration = new RegistrationBuilder();
registration.ForType<Node>().Export<INode>();
var catalog = new AssemblyCatalog(typeof(Node).Assembly, registration);
var container = new CompositionContainer(catalog);

Another way would be to inherit Node in your own code and export it: 另一种方法是在您自己的代码中继承Node并导出它:

[Export(typeof(INode))]
class MyNode : Node { }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM