MEF to load DLL one by one

I try to use MEF to load the DLL as needed, but the information in the tutorials that I read was not the most useful.

This site provides some code (shown below), but doesn’t actually 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 the Run method, and I implement this interface with several DLLs. What I need to do is do something like this (pseudo code)

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

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

+3
source share
2 answers

: MEF (dll) , Executing assembly, dll. ? , , , AssemblyCatalog .

+2

, , MEF, . (. Codeplex), , CCI.

MEF , ( mef).

+1

Source: https://habr.com/ru/post/1776725/


All Articles