Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mef import all types implementing an interface specified at runtime

Tags:

c#

.net

c#-4.0

mef

Can i write a class to use mef to import all types implementing a specific interface and then specify this interface at run time. (i know i need to tag the implementors with export)

Example usage:

IEnumerable<IExcitingClass> excitingClasses = ClassImporter<IExcitingInterface>.ImportAllFrom(specifyDirectory);

Is this possible?

like image 896
GreyCloud Avatar asked Mar 08 '26 10:03

GreyCloud


1 Answers

You can create a container using a DirectoryCatalog, and call container.GetExportedValues<IExcitingClass>. Is that what you want?

like image 79
Daniel Plaisted Avatar answered Mar 11 '26 00:03

Daniel Plaisted