李sir_Blog

博客园 首页 联系 订阅 管理

1:新建一个主题工程MEFOwn

2:新建一个接口DLL,定义为InterFace,

3:新建插件,引用这个接口,以及微软的ComponentModel.Composition

4:   调整命名空间,保持一致

5:插件处导出 [Export(typeof(IPlugin))],  实现接口

6:主工程处,引用接口,引用微软的ComponentModel.Composition

本身作为一个容器,将目录下所有的插件DLL,都加载到容器中

CompsitionContainer _container;

var catalog = new AggregateCatalog();

.....Add  

this._container.ComposeParts(this)

 

      [ImportMany]

      public IEnumerable<IPlugin> plugins;

    

 

posted on 2021-12-10 09:18  李sir  阅读(46)  评论(0编辑  收藏  举报