开发者

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 rea开发者_StackOverflowlly appreciate it!


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜