最近在做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. Git分支中的远程操作实践

    Git分支中的远程操作实践 前几篇博客陆陆续续的讲了好多关于Git操作的内容, 其中在上篇博客聊了<Git中的merge.rebase.cherry-pick以及交互式rebase>,本篇 ...

  2. 在另一个线程中无法用((CMainFrame *)AfxGetMainWnd())

    一个vc6的项目放到vc8下重新编译这里死活过不去 查了些资料无果后来翻到一句老外的回答 If AfxGetMainWnd is called from the application’s prima ...

  3. JS 之 数据类型转换

          首先我们来简单了解一下JS中的数据类型,JavaScript拥有字符串.数字.布尔.数组.对象.Null.Undefiend 6中数据类型.同一时候,JavaScript拥有动态类型. 也 ...

  4. npm ERR! fatal: unable to connect to github.com

    https://blog.csdn.net/baidu_30809315/article/details/86520093 git config --global url."https:// ...

  5. 【转】soapUI和Jmeter的接口测试结构区别

    使用SoapUI和Jmeter都可以进行自动化接口测试,但是每个工具都有自身的特点,所以他们的结构也有一定的区别 SoapUI 项目名称 -Rest服务.Rest资源 在使用SoapUI进行接口测试时 ...

  6. 使用@Scheduled注解编写spring定时任务

    import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframewor ...

  7. 发送邮件 Email(java实现)

    //发送邮件 private static void sendMail(String mail, String mailContext) { try { //获取文本中html的内容 并动态替换并显示 ...

  8. 九度OJ 1160:放苹果 (DFS)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:998 解决:680 题目描述: 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和 ...

  9. 九度OJ 1158:买房子 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1801 解决:1096 题目描述: 某程序员开始工作,年薪N万,他希望在中关村公馆买一套60平米的房子,现在价格是200万,假设房子价格以每 ...

  10. Richard Stallman's computer

    What hardware do you use? I am using a Lemote Yeelong, a netbook with a Loongson chip and a 9-inch d ...