利用MEF实现插件机制(可根据输入类型来加载特定dll)
- 最近在做PACS的项目中想利用插件来加载各个不同的SCP的操作实现。比如Worklist的查询数据库,可以有多个实现。 比如MPPS的更新,也可以有多个实现。 为了统一弹性处理插件模块,增加了类型输入,用来只加载特定的服务的实现。
- [InheritedExport(typeof(ISCPBase))]
- public interface ISCPBase
- {
- ISCPCfg SCPCfg
- {
- get;
- set;
- }
- string CustomModuleName
- {
- get;
- }
- }
- public class CustomExtensionManager
- {
- [ImportMany(typeof(ISCPBase), AllowRecomposition = true)]
- public IEnumerable<ISCPBase> CustomModules { get; set; }
- public CompositionContainer Container;
- private Type[] _filterTypes;
- private ModulesManagerCfg _mgrCfg;
- public ModulesManagerCfg ModulesManagerConfig
- {
- get
- {
- if (_mgrCfg == null)
- {
- try
- {
- _mgrCfg = XmlSerializeHelper<ModulesManagerCfg>.LoadFromFile(@"ModulesManagerCfg.xml");
- }
- catch (Exception ex)
- {
- Logger.ErrorWithFormat("Failed to load ModulesManagerCfg from ModulesManagerCfg.xml. {0}", ex.Message);
- }
- if (_mgrCfg == null)
- Logger.Error("ModulesManagerCfg is null, please check whether ModulesManagerCfg.xml exists.");
- }
- return _mgrCfg;
- }
- }
- /// <summary>
- /// Initialize the custom modules by interface type. It is well you can spec types.
- /// If you do not care types, you can pass null. It will load all modules if inherited from ISCPBase.
- /// </summary>
- /// <param name="scpTypes">The type that inherited from ISCPBase. Like IWorklistQuery...</param>
- public void Initialize(params Type[] scpTypes)
- {
- try
- {
- if (null != scpTypes)
- {
- _filterTypes = scpTypes;
- var catalog = new AggregateCatalog(new TypeCatalog(scpTypes), new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
- Container = new CompositionContainer(catalog);
- }
- else
- {
- var catalog = new AggregateCatalog(new TypeCatalog(scpTypes), new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
- Container = new CompositionContainer(catalog);
- }
- Container.ComposeParts(this);
- }
- catch (Exception ex)
- {
- Logger.ErrorWithFormat("Failed to initialize CustomExtensionManager. {0}", ex.Message);
- }
- }
- public ISCPBase GetCurrentUsedModule()
- {
- if (null == ModulesManagerConfig)
- {
- throw new ArgumentNullException("ModulesManagerCfg is null, please check whether ModulesManagerCfg.xml exists.");
- }
- if (String.IsNullOrEmpty(ModulesManagerConfig.CurrentUsedModuleName))
- {
- throw new Exception("CurrentUsedModuleName is empty, please check ModulesManagerCfg.xml.");
- }
- if (null == Container)
- {
- throw new Exception("Modules container is null, you can check your custom module and call Initialize() function to load modules.");
- }
- //var m = _container.GetExports<ISCPBase>()
- // .Where(e => e.Value.CustomModuleName.Equals(ModulesManagerConfig.CurrentUsedModuleName))
- // .FirstOrDefault();
- //if (null != m)
- //{
- // return m.Value;
- //}
- //return null;
- if (null == _filterTypes)
- {
- var m = CustomModules.FirstOrDefault(e => e.CustomModuleName.Equals(ModulesManagerConfig.CurrentUsedModuleName));
- return m;
- }
- else
- {
- var m = from c in CustomModules
- where _filterTypes.All(f => f.IsAssignableFrom(c.GetType()))
- select c;
- return m.FirstOrDefault();
- }
- }
- }
利用MEF实现插件机制(可根据输入类型来加载特定dll)的更多相关文章
- 一个页面从输入URL到加载显示完成,发生了什么?
面试经典题--URL加载 一.涉及基本知识点: 1. 计算机网络 五层因特尔协议栈: 应用层(dns.http):DNS解析成IP并完成http请求发送: 传输层(tcp.udp):三次握手四次挥手模 ...
- 插件化框架解读之so 文件加载机制(四)
阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680 提问 本文的结论是跟着 System.loadlibrary() ...
- QT/C++插件式框架、利用智能指针管理内存空间的实现、动态加载动态库文件
QT.C++插件式框架.主要原理还是 动态库的动态加载. dlopen()函数.下面为动态加载拿到Plugininstance对应指针.void**pp=(void**)dlsym(handle,&q ...
- WebApi 插件式构建方案:发现并加载程序集
插件式的 WebApi 开发,首要面对的问题就是程序集的发现.因为开发的过程中,都是在各自的解决方案下进行开发,部署后是分模块放在一个整体的的运行时网站下. 约定 这里我根据上一节的设定,把插件打包完 ...
- 从零开始实现ASP.NET Core MVC的插件式开发(一) - 使用ApplicationPart动态加载控制器和视图
标题:从零开始实现ASP.NET Core MVC的插件式开发(一) - 使用Application Part动态加载控制器和视图 作者:Lamond Lu 地址:http://www.cnblogs ...
- 使用jquery插件实现图片延迟加载技术(懒加载)
有时我们看到一些大型网站,页面如果有很多图片的时候,当你滚动到相应的行时,当前行的图片才即时加载的,这样子的话页面在打开只加可视区域的图片,而其它隐藏的图片则不加载,一定程序上加快了页面加载的速度,对 ...
- Android 插件化开发(二):加载外部Dex文件
在学习Java反射的技术后,我们可以开始更深一步的探究插件化开发了.首先先讲一下Android App的打包流程,然后我们通过一个简单的例子 —— 实现插件化加载外部Dex来完成初级的插件化开发的探索 ...
- 如何结合插件 vue-lazyload 来简单实现图片懒加载?
插件地址:https://www.npmjs.com/package/vue-lazyload: 一.使用场景: 在项目中有很多条数的信息,且图片很多的时候,不需要一次把整个页面的图片都加载完,而是在 ...
- 利用Javascript解决HTML大数据列表引起的网页加载慢/卡死问题。
在一些网页应用中,有时会碰到一个超级巨大的列表,成千上万行,这时大部份浏览器解析起来就非常痛苦了(有可能直接卡死). 也许你们会说可以分页或动态加载啊?但是有可能需求不允许分页,动态加载?网络的延迟也 ...
随机推荐
- 在4x4的棋盘上摆满了黑白棋子,黑白两色的位置和数目随机其中左上角坐标为(1,1),右下角坐标为(4,4),现在依次有一些翻转操作,要对一些给定支点坐标为中心的上下左右四个棋子的颜色进行翻转,请计算出翻转后的棋盘颜色。
// ConsoleApplication10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...
- python os模块 常用函数
os.getcwd() 获取当前工作目录 os.listdir() 返回指定目录下的所有文件和目录 os.remove() 删除单个文件 os.path.split() 以元祖形式返回一个路径的目录和 ...
- MongoDB--安装部署
MongoDB安装 说明: 本次安装教程: 版本:mongoDB-3.2.4 安装环境:windows 10 ,64位操作系统 准备:安装包.Robomongo(客户端用于查看mongoDB里面的数据 ...
- Jquery获取iframe中的元素
iframe与父页面之间相互获取元素的方法: 1.从父页面中获取iframe页面中的元素: 用法: $(window.frames["iframe_include_adverse" ...
- Cocos2d-x 3.0final 终结者系列教程16-《微信飞机大战》实现
看到cocos2d-x推出了3.1版本号,真是每月一次新版本号,速度. 另一个好消息就是http://cn.cocos2d-x.org/上线了,祝贺!啥时候把我的视频和教程放上去呢?!! . 视频下载 ...
- 大白第一章第四节dp例题
入口 UVALive - 3882 #include<cstdio> using namespace std; ; int n,m,k,f[N]; int main(){ //f[i]表示 ...
- EasyNVR RTSP转RTMP-HLS流媒体服务器前端构建之:使用BootstrapPagination以分页形式展示数据信息
上一篇介绍通过接口来获取数据,本篇将介绍如何以分页形式展示出接口获取到的数据 获取到的数据往往会很多,为了追去页面的美观和方便用户的检索,需要进行分页的展示: EasyNVR可接如多通道,当我们的通道 ...
- 开发过程中,本地分支和远程跟踪分支发生了diverge
1 git基本概念梳理 1.1 git的工作目录.暂存区和HEAD指向的版本库以及branch的概念 一个branch就是整个产品的一套代码,而工作目录中就是存放的本branch最新的代码,HEAD指 ...
- 前端几个笔试题及答案(bd)
1. 行内元素.块级元素和空元素(void)举例. 块级元素:<address>.<caption>.<dd>.<div>.<dl>.& ...
- 【linux】top更改排序顺序
top更改排序顺序的方式有很多,这里介绍两个比较简单使用的. 1,快捷键: 大写M:根据内存排序,默认从大到小,大写R更改为从小到大排序 大写P:根据CPU使用排序,默认从大到小,大写R更改为从小到大 ...