mef

Change Dll loaded with MEF

荒凉一梦 提交于 2020-01-01 05:47:08
问题 I'm using MEF and the System.ComponentModel.Composition.dll to load some dll. I'm doing something like : AggregateCatalog catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()), new DirectoryCatalog(directory)); _container = new CompositionContainer(catalog); _container.ComposeParts(this); to import my dll. After some times, I would like to update my dll but if I try to delete it, I have an access denied, because it's alrealdy used by the program. How can I

How to prioritize different catalogs in MEF?

一笑奈何 提交于 2020-01-01 05:37:50
问题 I have a AggregateCatalog that contains an AssemblyCatalog and a DirectoryCatalog. I want them to work like this: If both catalogs can find an export, choose the one from the DirectoryCatalog. If neither of them can find an export, then just leave the import to be null. If only one of them can find an export, then just use that export to fill the import. How can I achieve something like this? 回答1: You can achieve point 1. and 3. by putting the catalogs in different export providers, and then

Using MEF as an IoC

不想你离开。 提交于 2020-01-01 04:09:05
问题 After reading some stuff such as this: http://mikehadlow.blogspot.com/2008/09/managed-extensibility-framework-why.html I understand that MEF has some featcures that I will not find in an IoC, and that MEF has some IoC stuff that is probaboly not as advanced as some other IoC systems can offer. I need the MEF stuff. Do I also need an IoC framework or would I be fine with what MEF has? Asher 回答1: Depends on your requirements/existing code. If you have an existing code infrastructure built on an

Prism 4 - locally scoped RegionManager

萝らか妹 提交于 2020-01-01 03:22:26
问题 I have silverlight 4 application with PRISM 4, I'm using MEF. My Shell defines one main region in which modules are loaded, I want modules to have their own RegionManager, so regions that they define are places in local RegionManager instead of global. And I want this local RegionManager to be resolved by container (for type IRegionManager) when inside the module. However the method from documentation: IRegion detailsRegion = this.regionManager.Regions["DetailsRegion"]; View view = new View()

MEF and MVC 3 - how to load embedded views dynamically from mef container?

那年仲夏 提交于 2020-01-01 02:30:12
问题 I'm building an MVC 3 application where MEF is used. The main idea is to have plug-in mechanism where models, controllers and views are loaded dynamically during runtime from mef container. Each plugin/module consists of two assemblies: Module1.Data.dll (contains definitions of models) Module1.Web.dll (contains controllers and views) and are put in the Plugins directory inside web application bin: WebApp/Bin/Plugins/Module1.Data.dll WebApp/Bin/Plugins/Module1.Web.dll WebApp/Bin/Plugins

How to use resource dictionary in prism modules at design time?

我只是一个虾纸丫 提交于 2019-12-31 16:02:21
问题 I am using prism framework in a silverlight app with multiple modules in separate XAPs. I have a resource dictionary defined in my in my shell project. In my modules I can use the resources fine, but since the modules are decoupled from the shell until they are loaded at runtime the designer does not show them or recognize them. Is there a way to make the modules aware of my resources at design time without merging my resource file in every view xaml? My resource files are in a "common"

C#可扩展编程之MEF学习笔记(四):见证奇迹的时刻

拈花ヽ惹草 提交于 2019-12-30 23:59:23
  前面三篇讲了MEF的基础和基本到导入导出方法,下面就是见证MEF真正魅力所在的时刻。如果没有看过前面的文章,请到我的博客首页查看。   前面我们都是在一个项目中写了一个类来测试的,但实际开发中,我们往往要采用分层架构,就拿最简单的三层架构来说吧,我们通常把业务逻辑写在DLL中,现在就来写一个例子,看看如何在不编译整个项目的情况下,轻松的实现扩展。先透露一下,我们只要添加一个DLL就可以了。   这里就以银行为例子吧,首先新建一个控制台项目,还叫MEFDemo吧,然后建一个类库写接口,然后再建一个类库实现接口。项目结构如下: MEFDemo和BankOfChina都只引用接口项目,MEFDemo不需要引用BankOfChina。 BankInterface的代码如下,做个简单实例,写几个方法测试一下: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BankInterface { public interface ICard { //账户金额 double Money { get; set; } //获取账户信息 string GetCountInfo(); //存钱 void SaveMoney(double money); //取钱

C#可扩展编程之MEF学习笔记(五):MEF高级进阶

☆樱花仙子☆ 提交于 2019-12-30 23:58:50
好久没有写博客了,今天抽空继续写MEF系列的文章。有园友提出这种系列的文章要做个目录,看起来方便,所以就抽空做了一个,放到每篇文章的最后。 前面四篇讲了MEF的基础知识,学完了前四篇,MEF中比较常用的基本已经讲完了,相信大家已经能看出MEF所带来的便利了。今天就介绍一些MEF中一些较为不常用的东西,也就是大家口中的所谓的比较高级的用法。 前面讲的导出都是在每个类上面添加Export注解,实现导出的,那么有没有一种比较简便的方法呢?答案是有的,就是在接口上面写注解,这样只要实现了这个接口的类都会导出,而不需要在每个类上面都写注解。下面仅贴出接口和一个实现类的源码,其余的模仿即可: 接口代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.Composition; namespace BankInterface { [InheritedExport] public interface ICard { //账户金额 double Money { get; set; } //获取账户信息 string GetCountInfo(); //存钱 void SaveMoney(double money); /

MEF & separate Interface assembly leads to “Interface for every class”

末鹿安然 提交于 2019-12-30 18:27:40
问题 I'm getting my feet wet with DI/IoC and MEF in particular. I have a web application that has two types of parts (maybe more someday) defined by interfaces which need access to the whole environment. The application has a list with concrete implementations for each type, composed by MEF. The environment consists of: several repositories current application request render engine navigation engine plus some static utility classes How can I put the Interface definitions in a seperate assembly and

MEF & separate Interface assembly leads to “Interface for every class”

社会主义新天地 提交于 2019-12-30 18:26:13
问题 I'm getting my feet wet with DI/IoC and MEF in particular. I have a web application that has two types of parts (maybe more someday) defined by interfaces which need access to the whole environment. The application has a list with concrete implementations for each type, composed by MEF. The environment consists of: several repositories current application request render engine navigation engine plus some static utility classes How can I put the Interface definitions in a seperate assembly and