最近在做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. STM32 I2C

    STM32 I2C 搞了几天了,比较郁闷,写点东西给那些正在郁闷的同志 // 好使的,也是范例的代码 cnt = TIME_OUT; while (cnt-- && !I2C_Chec ...

  2. 2018年EMUI系统能力分论坛来啦

    为鼓励开发者创新,挖掘前沿创新能力的应用及服务,帮开发者打造爆款应用的同时丰富终端消费者的用户体验,由设立10亿激励基金耀星计划扶持的华为创新竞赛平台即将开启. 竞赛平台将滚动推出AI.HAG.AR. ...

  3. LRM-00109: could not open parameter file

    SQL>startup                                                                                       ...

  4. 【spring配置】——spring整合Quartz定时器

    第一种:为普通java类中的某个方法配置跑批任务 MethodInvokingJobDetailFactoryBean CronTriggerBean SchedulerFactoryBean 1.定 ...

  5. Spring Boot启动原理解析

    Spring Boot启动原理解析http://www.cnblogs.com/moonandstar08/p/6550758.html 前言 前面几章我们见识了SpringBoot为我们做的自动配置 ...

  6. 九度OJ 1025:最大报销额 (01背包、DP)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4352 解决:1055 题目描述:     现有一笔经费可以报销一定额度的发票.允许报销的发票类型包括买图书(A类).文具(B类).差旅(C ...

  7. 该 Bucket 已存在,或被其他用户占用

  8. a positive definite matrix

    https://en.wikipedia.org/wiki/Definite_quadratic_form https://www.math.utah.edu/~zwick/Classes/Fall2 ...

  9. 性能优化——Web前端性能优化

    核心知识点: 1.排查网站性能瓶颈的手法:分析各个环节的日志,找出异常部分 2.Web前端:网站业务逻辑之前的部分(浏览器.图片服务.CDN) 3.优化手段 1)浏览器优化 (1)减少http请求 a ...

  10. Java一致性的实现

    一致性     内存模型 每一个线程有一个工作内存和主存独立 工作内存存放主存中变量的值的拷贝     Happen Before 1.程序次序规则:在一个单独的线程中,按照程序代码的执行流顺序,(时 ...