最近在做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)的更多相关文章

  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. WARN util.NativeCodeLoader: Unable to load native-hadoop l... using builtin-java classes where applicable(附编译脚本)

    WARN util.NativeCodeLoader: Unable to load native-hadoop l... using builtin-java classes where appli ...

  2. linux支持的machine-types

    在内核文件中arch/arm/tools/mach-types定义目前内核支持的板卡.芯片等: ##machine_is_xxx  CONFIG_xxxx  MACH_TYPE_xxx  number ...

  3. Rider

    听说你开发.NET还在用VS,小哥哥给你推荐全平台的Rider   本文地址:http://www.cnblogs.com/likeli/p/8461010.html 前言 .NET平台的开发一直都只 ...

  4. 详解spring boot实现多数据源代码实战

    之前在介绍使用JdbcTemplate和Spring-data-jpa时,都使用了单数据源.在单数据源的情况下,Spring Boot的配置非常简单,只需要在application.propertie ...

  5. win10 64位 安装TensorFlow

    .由于之前安装的是python2.7 ,tensorflow在windows下必须要python3 网上查了一下有三种方法2版本共存 1.不用Anaconda windows 安装python2 与p ...

  6. LR中select next row和update value on的设置

    LR的参数的取值,和select next row和update value on的设置都有密不可分的关系.下表给出了select next row和update value on不同的设置,对于LR ...

  7. N皇后问题算法

    N皇后问题的两种主要算法是试探回溯法和位运算法.前一种是经典算法,后一种是目前公认的最高效算法,后者比前者效率提高了至少一个数量级.很多问题可以借鉴位运算的思想. 以下是转载的我认为写的比较好的一篇N ...

  8. Open-sourcing LogDevice, a distributed data store for sequential data

    https://logdevice.io/blog/2018/09/12/open-sourcing-announcement.html September 12, 2018   We are exc ...

  9. Java中Iterator的fast-fail分析

    1.fail-fast简介 fail-fast机制是java集合(Collection)中的一个错误机制.当多个线程对同一个集合的内容进行操作时,就可能会产生fail-fast事件. 例如:当某一个线 ...

  10. Flask中的内置session

    Flask中的Session非常的奇怪,他会将你的SessionID存放在客户端的Cookie中,使用起来也非常的奇怪 1. Flask 中 session 是需要 secret_key 的 from ...