Dipke
Dipke

Reputation: 17

Single .dll with MEF

With reflection i can load a single dll.

Assembly testAssembly = Assembly.LoadFile(@"c:\Test.dll");

But with MEF all the plugins in the directory are red. Is there a way with MEF of doing the same ?

I can do this :

public IPlugn Load(string name)
    {
        return Plugins
          .Where(l => l.Name.Equals(name))
          .FirstOrDefault();
    }

but this is a based on the the whole list of plugins.

Kind regards

Dipke

Upvotes: 1

Views: 464

Answers (1)

RB.
RB.

Reputation: 37212

Catalogs are the mechanism MEF uses to find plugins - and they are very flexible.

You are presumably using a DirectoryCatalog?

If so, you can use the overload of the constructor that takes a search pattern:

var catalog = new DirectoryCatalog("C:\\", "Test.dll");

Alternatively, you can use the AssemblyCatalog, which will allow you to just specify the assembly to use.

var catalog = new AssemblyCatalog(Assembly.LoadFile("C:\\Test.dll"));

Finally, if you want any really specific behaviour (load plugins from a web-service call, or crazy stuff like that), then you can just implement your own ComposablePartCatalog.

Upvotes: 2

Related Questions