m4rc
m4rc

Reputation: 3006

MEF to load DLL one by one

I am trying to use MEF to load a DLL as an when it is needed, however, the information in tutorials I have read hasn't been the most helpful.

This site gives a bit of code (shown below) but doesn't really explain anything.

private void LoadPlugins() {
  var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
  var container = new CompositionContainer(catalog);
  var batch = new CompositionBatch();
  batch.AddPart(this);
  container.Compose(batch);
}

Basically I have an interface with a Run method and I am implementing that interface with several DLLs. What I'm after is to be able to do something like this (pseudo code)

bob = LoadDll(dllPath);
bob.Run();

Is there a way to specify the type of "bob" or would it be generic? If anyone can help I would really appreciate it!

Upvotes: 3

Views: 3567

Answers (2)

hammett
hammett

Reputation: 725

What you want can be accomplished with MEF, but it's quite advanced. You either need to construct a cached catalog (see sample in our Codeplex site) or use a different metadata reader such as CCI.

Out of the box MEF will load assemblies to reflect on them (looking for mef's attributes).

Upvotes: 1

akonsu
akonsu

Reputation: 29586

does this article help: MEF Load Plugins(dlls) from folder not in Executing assembly but another dll.Can you help? basically, the solution, i think, would be to use AssemblyCatalog to load your assembly.

Upvotes: 2

Related Questions