zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    jquery插件treetable使用
    WPF界面按钮美化
    Nginx配置
    Spring Framework之AOP
    IOS抓取与反抓取
    Spring Framework之事务管理
    68- 二叉树的最近公共祖先
    Spring Framework之IoC容器
    应试教育引发的思考
    春季实习生校园招聘总结
  • 原文地址:https://www.cnblogs.com/zeroone/p/5638788.html
Copyright © 2011-2022 走看看