简体   繁体   中英

WPF MEF and 3rd party library

I have 3rd party dll and in this dll is such hierarchy: class Node realize interface INode. This dll uses Ninject binding in it. My application uses this dll and Prism and MEF as IoC container. I haven't practice in Prism and MEF before, so one thing I want to do is to bind INode to Node. I don't have access to INode and Node, so write smth like that I can't:

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

In Ninject I would did it in such way:

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

Can I do something like that in MEF? Thnx.

Have a look at MEF's Convention Model . 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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