Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MEF: Mark interface for export

Tags:

.net

mef

Is it possible to mark an interface for export, so that all derived classes will be available for import?

[Export( typeof( IMyInterface ) )]
public interface IMyInterface { ... }

[Import( typeof( IMyInterface ) )]
private readonly ICollection<IMyInterface> m_Concretes = new Collection<IPlugin>();

I don't know which classes are implementing IMyInterface in this example. The classes themselves do not know anything about MEF - and do not use the [Export] attribute.

As long as I do not mark every single class with [Export] it doesn't seem to work for me.

like image 319
tanascius Avatar asked Jan 23 '23 12:01

tanascius


1 Answers

In the current preview, you can try putting a [PartExportsInherited] attribute on the interface (along with the Export attribute). I'm not sure whether this will work for interfaces or not, though.

We do plan to add support to putting exports on interfaces.

like image 172
Daniel Plaisted Avatar answered Jan 26 '23 00:01

Daniel Plaisted