mef

.Net4下的MEF(Managed Extensibility Framework) 架构简介

你说的曾经没有我的故事 提交于 2019-12-04 09:37:05
阅读: 1279 评论: 4 作者: 周 金根 发表于 2010-05-26 21:08 原文链接 在上篇 WPF -.Net 4.0解决了DataGrid分组时的内存泄露 中说过由于内存泄露问题, OpenExpressApp 升级到.Net4平台,然后升级后之前的 compositewpf 出了点问题。在OpenExpressApp考虑动态扩展组件机制方面,以前就考虑过 MEF ,但当时还不成熟,所以使用了compositewpf,而现在MEF已经成为了.Net第一公民,compositewpf又没有提供.Net4的版本,也很久没有升级了,也不明确它的发展方向,并且现在软件中有些内存泄露问题也与它有关,所以干脆使用MEF作为插件机制。这里把这两个一起提出,主要是从动态扩充组件来说的,它们实际上不是一个东西,可以并存的,在这里就不多说这些了,下面我主要介绍一下MEF的架构,希望从总体上有所了解,更改OpenExpressApp后我会再写篇文章介绍一下如何在OpenExpressApp中使用MEF的。 主要示意图 各种Export提供者从目录提取part信息,然后由CompositionContainer进行装配,其中每个part都包含Import和Export两部分内容。 主要组成图 由容器、基础类库和属性编程模型组成,组成东西其实不多,要想扩充自己的东西必须熟悉这些东西。

MEF parts configuration, where to store?

China☆狼群 提交于 2019-12-04 08:52:56
In ASP.NET , .NET 4.0 , MEF , I put all parts in a folder and importing them using DirectoryCatalog . Everything is fine. Some of part have related configurations. I don't want put them in web.config . Maybe a good approach be a config file just beside the part with a .config added to the end. What is the best way for storing part configuration ? I was able to create a separate config file for each DLL and successfully was able to read the keys. But when I tried to create a custom config section, I was not able to read from the DLL's app config. It always wanted to read from the MEF Consumer

How to use MEF Inherited Export & MetaData?

坚强是说给别人听的谎言 提交于 2019-12-04 08:24:14
问题 I have an interface: [InheritedExport(typeof(IMetric))] public interface IMetric { ... } I have a Meta attribute interface: public interface IMetricAttribute { ... } and an attribute that implements it: [MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class MetricAttribute : ExportAttribute, IMetricAttribute { public string MetricName { get; set; } public string MetricDescription { get; set; } public MetricAttribute(string name, string description) :

Managed Extensibility Framework (MEF) vs. Composite UI Application Block (CAB)

北城以北 提交于 2019-12-04 08:18:11
We are currently looking at either using CAB or MEF for our next application. I didn't see any examples on codeplex of how event brokering is handled for sibling control communication, maybe I missed it. How does inter-control communication work in MEF? Also, we are planning on using Infragistics which has provided additional components for the CAB framework. How well will Infragistics controls integrate into MEF? Overall, is MEF worth pursuing for a decently large, 15,000 hours of strictly development, application? I may be wrong but I don't think that MEF has any event brokering. It is a

Custom configuration sections in MEF exporting assemblies

可紊 提交于 2019-12-04 06:39:29
I have an assembly that contains classes that import a number of classes from different assemblies that are not referenced at compile time but are discovered at runtime via a directory catalog. The exporting classes want to define custom configuration sections for the config file in the importing assembly's host application. However, because the importing assembly's host application does not know the exporting assemblies at compile time, it cannot load the assembly to use the custom section handler implementations in them. One way I have found to work around this is to put the exporting

Get the current filename from a Visual Studio text adornment extension

风格不统一 提交于 2019-12-04 06:33:21
I'm new to VS extension development. I'm currently working with the text adornment sample in VS 2015 and have been able to get coloured boxes showing correctly. Now I want to extend the sample so the adornment only appears on certain file names. Googling has said I can use ITextDocumentFactoryService.TryGetTextDocument interface with the IWpfTextView.TextBuffer property to get a filename. This sounds great. But I can't seem to actually get the interface. In my class I have: [Import] public ITextDocumentFactoryService TextDocumentFactoryService = null; But it is always NULL. How can I get

C# WCF plugin design and implementation

浪子不回头ぞ 提交于 2019-12-04 04:51:32
I would like to get some advice. I am developing a system that will load up plugins at runtime and require them to be available through a WCF endpoint. I will have a MVC 3 Web app that is only really used for configuration, and a class library (core) that will load up different plugins. I would appreciate some guidance on how to go about this. I would like to load the plugin up and then be able to create a WCF endpoint that is registered with IIS 7 for access into that plugin. Thanks in advance :) Using a derivative of Darko's Dynamic IIS hosted WCF Service work, you can achieve something what

how to debug MEF exception?

你离开我真会死。 提交于 2019-12-04 03:38:16
问题 we are currently using MEF (Managed Extensibility Framework, http://mef.codeplex.com/ ) and it throws out exceptions, with limited information to proceed on. is there a way to debug MEF exceptions? My exception is like this: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes()

Lazy Loading DLL's with MEF

心已入冬 提交于 2019-12-04 03:32:13
问题 I'm doing my first project with MEF and am seriously unable to understand how to use lazy loading. My code is - public static class MefLoader { private static CompositionContainer Container; [ImportMany(typeof(IControlModule), AllowRecomposition = true)] private static IEnumerable<Lazy<IControlModule, IImportComponentCapabilites>> DllList { get; set; } static MefLoader() { var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new DirectoryCatalog(".")); Container = new

What does [PartCreationPolicy(CreationPolicy.Shared)]

て烟熏妆下的殇ゞ 提交于 2019-12-04 03:02:33
What does [PartCreationPolicy(CreationPolicy.Shared)] mean? To add to Julien's answer, I think conceptually you can think of it as a Singleton . It means that, when requesting an instance of a class decorated with [PartCreationPolicy(CreationPolicy.Shared)] , the CompositionContainer will always return the same instance of this class and not create a new one. [Export] [PartCreationPolicy(CreationPolicy.Shared)] class Foo { } The above class will give the following result: private void Test() { var foo1 = Container.GetExportedValue<Foo>(); var foo2 = Container.GetExportedValue<Foo>(); Console