MEF load plugin from directory

var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog("."));
var container = new CompositionContainer(catalog);
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new DirectoryCatalog("."));
var container = new CompositionContainer(catalog);
public void AssembleCalculatorComponents()
{ string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");
Console.WriteLine(path);
//Check the directory exists
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
Console.WriteLine(path);
string assemblyName = Assembly.GetEntryAssembly().FullName;
Console.WriteLine(assemblyName);
//Create an assembly catalog of the assemblies with exports
var catalog = new AggregateCatalog(
new AssemblyCatalog(Assembly.GetExecutingAssembly().Location),
new AssemblyCatalog(Assembly.Load(assemblyName)),
new DirectoryCatalog(path, "*.dll")); //Create a composition container
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
上一篇:mysql主从同步(4)-Slave延迟状态监控


下一篇:AdminLTE-2.2.0 学习