1. 最近在做PACS的项目中想利用插件来加载各个不同的SCP的操作实现。比如Worklist的查询数据库,可以有多个实现。 比如MPPS的更新,也可以有多个实现。 为了统一弹性处理插件模块,增加了类型输入,用来只加载特定的服务的实现。
  1. [InheritedExport(typeof(ISCPBase))]
  2. public interface ISCPBase
  3. {
  4. ISCPCfg SCPCfg
  5. {
  6. get;
  7. set;
  8. }
  9.  
  10. string CustomModuleName
  11. {
  12. get;
  13. }
  14. }
  1.  
  1.  
  1. public class CustomExtensionManager
  2. {
  3. [ImportMany(typeof(ISCPBase), AllowRecomposition = true)]
  4. public IEnumerable<ISCPBase> CustomModules { get; set; }
  5.  
  6. public CompositionContainer Container;
  7.  
  8. private Type[] _filterTypes;
  9.  
  10. private ModulesManagerCfg _mgrCfg;
  11. public ModulesManagerCfg ModulesManagerConfig
  12. {
  13. get
  14. {
  15. if (_mgrCfg == null)
  16. {
  17. try
  18. {
  19. _mgrCfg = XmlSerializeHelper<ModulesManagerCfg>.LoadFromFile(@"ModulesManagerCfg.xml");
  20. }
  21. catch (Exception ex)
  22. {
  23. Logger.ErrorWithFormat("Failed to load ModulesManagerCfg from ModulesManagerCfg.xml. {0}", ex.Message);
  24. }
  25.  
  26. if (_mgrCfg == null)
  27. Logger.Error("ModulesManagerCfg is null, please check whether ModulesManagerCfg.xml exists.");
  28. }
  29.  
  30. return _mgrCfg;
  31. }
  32. }
  33.  
  34. /// <summary>
  35. /// Initialize the custom modules by interface type. It is well you can spec types.
  36. /// If you do not care types, you can pass null. It will load all modules if inherited from ISCPBase.
  37. /// </summary>
  38. /// <param name="scpTypes">The type that inherited from ISCPBase. Like IWorklistQuery...</param>
  39. public void Initialize(params Type[] scpTypes)
  40. {
  41. try
  42. {
  43. if (null != scpTypes)
  44. {
  45. _filterTypes = scpTypes;
  46.  
  47. var catalog = new AggregateCatalog(new TypeCatalog(scpTypes), new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
  48.  
  49. Container = new CompositionContainer(catalog);
  50. }
  51. else
  52. {
  53. var catalog = new AggregateCatalog(new TypeCatalog(scpTypes), new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
  54.  
  55. Container = new CompositionContainer(catalog);
  56. }
  57.  
  58. Container.ComposeParts(this);
  59. }
  60. catch (Exception ex)
  61. {
  62. Logger.ErrorWithFormat("Failed to initialize CustomExtensionManager. {0}", ex.Message);
  63. }
  64. }
  65.  
  66. public ISCPBase GetCurrentUsedModule()
  67. {
  68. if (null == ModulesManagerConfig)
  69. {
  70. throw new ArgumentNullException("ModulesManagerCfg is null, please check whether ModulesManagerCfg.xml exists.");
  71. }
  72.  
  73. if (String.IsNullOrEmpty(ModulesManagerConfig.CurrentUsedModuleName))
  74. {
  75. throw new Exception("CurrentUsedModuleName is empty, please check ModulesManagerCfg.xml.");
  76. }
  77.  
  78. if (null == Container)
  79. {
  80. throw new Exception("Modules container is null, you can check your custom module and call Initialize() function to load modules.");
  81. }
  82.  
  83. //var m = _container.GetExports<ISCPBase>()
  84. // .Where(e => e.Value.CustomModuleName.Equals(ModulesManagerConfig.CurrentUsedModuleName))
  85. // .FirstOrDefault();
  86.  
  87. //if (null != m)
  88. //{
  89. // return m.Value;
  90. //}
  91.  
  92. //return null;
  93.  
  94. if (null == _filterTypes)
  95. {
  96. var m = CustomModules.FirstOrDefault(e => e.CustomModuleName.Equals(ModulesManagerConfig.CurrentUsedModuleName));
  97. return m;
  98. }
  99. else
  100. {
  101. var m = from c in CustomModules
  1. where _filterTypes.All(f => f.IsAssignableFrom(c.GetType()))
  1. select c;
  1.  
  2. return m.FirstOrDefault();
  3. }
  4. }
  5. }

利用MEF实现插件机制(可根据输入类型来加载特定dll)的更多相关文章

  1. 一个页面从输入URL到加载显示完成,发生了什么?

    面试经典题--URL加载 一.涉及基本知识点: 1. 计算机网络 五层因特尔协议栈: 应用层(dns.http):DNS解析成IP并完成http请求发送: 传输层(tcp.udp):三次握手四次挥手模 ...

  2. 插件化框架解读之so 文件加载机制(四)

    阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680 提问 本文的结论是跟着 System.loadlibrary() ...

  3. QT/C++插件式框架、利用智能指针管理内存空间的实现、动态加载动态库文件

    QT.C++插件式框架.主要原理还是 动态库的动态加载. dlopen()函数.下面为动态加载拿到Plugininstance对应指针.void**pp=(void**)dlsym(handle,&q ...

  4. WebApi 插件式构建方案:发现并加载程序集

    插件式的 WebApi 开发,首要面对的问题就是程序集的发现.因为开发的过程中,都是在各自的解决方案下进行开发,部署后是分模块放在一个整体的的运行时网站下. 约定 这里我根据上一节的设定,把插件打包完 ...

  5. 从零开始实现ASP.NET Core MVC的插件式开发(一) - 使用ApplicationPart动态加载控制器和视图

    标题:从零开始实现ASP.NET Core MVC的插件式开发(一) - 使用Application Part动态加载控制器和视图 作者:Lamond Lu 地址:http://www.cnblogs ...

  6. 使用jquery插件实现图片延迟加载技术(懒加载)

    有时我们看到一些大型网站,页面如果有很多图片的时候,当你滚动到相应的行时,当前行的图片才即时加载的,这样子的话页面在打开只加可视区域的图片,而其它隐藏的图片则不加载,一定程序上加快了页面加载的速度,对 ...

  7. Android 插件化开发(二):加载外部Dex文件

    在学习Java反射的技术后,我们可以开始更深一步的探究插件化开发了.首先先讲一下Android App的打包流程,然后我们通过一个简单的例子 —— 实现插件化加载外部Dex来完成初级的插件化开发的探索 ...

  8. 如何结合插件 vue-lazyload 来简单实现图片懒加载?

    插件地址:https://www.npmjs.com/package/vue-lazyload: 一.使用场景: 在项目中有很多条数的信息,且图片很多的时候,不需要一次把整个页面的图片都加载完,而是在 ...

  9. 利用Javascript解决HTML大数据列表引起的网页加载慢/卡死问题。

    在一些网页应用中,有时会碰到一个超级巨大的列表,成千上万行,这时大部份浏览器解析起来就非常痛苦了(有可能直接卡死). 也许你们会说可以分页或动态加载啊?但是有可能需求不允许分页,动态加载?网络的延迟也 ...

随机推荐

  1. 在4x4的棋盘上摆满了黑白棋子,黑白两色的位置和数目随机其中左上角坐标为(1,1),右下角坐标为(4,4),现在依次有一些翻转操作,要对一些给定支点坐标为中心的上下左右四个棋子的颜色进行翻转,请计算出翻转后的棋盘颜色。

    // ConsoleApplication10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...

  2. python os模块 常用函数

    os.getcwd() 获取当前工作目录 os.listdir() 返回指定目录下的所有文件和目录 os.remove() 删除单个文件 os.path.split() 以元祖形式返回一个路径的目录和 ...

  3. MongoDB--安装部署

    MongoDB安装 说明: 本次安装教程: 版本:mongoDB-3.2.4 安装环境:windows 10 ,64位操作系统 准备:安装包.Robomongo(客户端用于查看mongoDB里面的数据 ...

  4. Jquery获取iframe中的元素

    iframe与父页面之间相互获取元素的方法: 1.从父页面中获取iframe页面中的元素: 用法: $(window.frames["iframe_include_adverse" ...

  5. Cocos2d-x 3.0final 终结者系列教程16-《微信飞机大战》实现

    看到cocos2d-x推出了3.1版本号,真是每月一次新版本号,速度. 另一个好消息就是http://cn.cocos2d-x.org/上线了,祝贺!啥时候把我的视频和教程放上去呢?!! . 视频下载 ...

  6. 大白第一章第四节dp例题

    入口 UVALive - 3882 #include<cstdio> using namespace std; ; int n,m,k,f[N]; int main(){ //f[i]表示 ...

  7. EasyNVR RTSP转RTMP-HLS流媒体服务器前端构建之:使用BootstrapPagination以分页形式展示数据信息

    上一篇介绍通过接口来获取数据,本篇将介绍如何以分页形式展示出接口获取到的数据 获取到的数据往往会很多,为了追去页面的美观和方便用户的检索,需要进行分页的展示: EasyNVR可接如多通道,当我们的通道 ...

  8. 开发过程中,本地分支和远程跟踪分支发生了diverge

    1 git基本概念梳理 1.1 git的工作目录.暂存区和HEAD指向的版本库以及branch的概念 一个branch就是整个产品的一套代码,而工作目录中就是存放的本branch最新的代码,HEAD指 ...

  9. 前端几个笔试题及答案(bd)

    1.   行内元素.块级元素和空元素(void)举例. 块级元素:<address>.<caption>.<dd>.<div>.<dl>.& ...

  10. 【linux】top更改排序顺序

    top更改排序顺序的方式有很多,这里介绍两个比较简单使用的. 1,快捷键: 大写M:根据内存排序,默认从大到小,大写R更改为从小到大排序 大写P:根据CPU使用排序,默认从大到小,大写R更改为从小到大 ...