Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting a MEF assembly at runtime

Tags:

c#

mef

I have a directory with many .dlls some of which are MEF plugins which I am loading using a DirectoryCatalog - for example:

var catalog = new DirectoryCatalog(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

This loads into the catalog all assemblies at hosts executing directory. However, I wish to only build a catalog of MEF assemblies (i.e. composable parts).

Is there a way to detect MEF assemblies?

like image 541
aateeque Avatar asked Feb 22 '23 12:02

aateeque


1 Answers

Those assemblies without MEF parts do not have any effect on DirectoryCatalog.Parts, so MEF already does the detection for you.

If you feel that the performance impact of scanning all assemblies for MEF parts is too high, then you can use a search pattern to filter on the DLL name like this:

var catalog = new DirectoryCatalog(
    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
    "*.plugins.dll");
like image 59
Wim Coenen Avatar answered Mar 08 '23 10:03

Wim Coenen