mef

MEF, can I export/import classes with multiple MetaDataAttribute decorations?

房东的猫 提交于 2019-12-11 09:08:31
问题 How can I make the following code work? It throws an error saying that there are two meta data attributes of identical names, though I do not see why. The error message is as follows: An unhandled exception of type 'System.InvalidOperationException' occurred in System.ComponentModel.Composition.dll Additional information: Member or Type 'ConsoleApplication2.DoSomeMagic' contains multiple metadata entries with the name 'PluginName'. The metadata entries could be coming from the

CompositionContainer loading wrong directory through DirectoryCatalog

こ雲淡風輕ζ 提交于 2019-12-11 09:07:23
问题 I'm running into an odd problem with MEF's composition container and directory catalog where I pass in a full path to a folder containing assemblies: In C:\Program Files\MyCompany\MyApp\Bin AssemblyA: ExportedTypeA, ExportedTypeB AssemblyB: BaseExportedTypeA, BaseExportedTypeB Executed from another location (C:\users\Me\dev\project\foo\bar\bar2\bin\debug\OtherApp.Exe) In the application I call: string ProviderPhysicalPath = @"C:\Program Files\MyCompany\MyApp\Bin"; using (DirectoryCatalog

MEF Lazy ImportMany with Creationpolicy.NonShared

有些话、适合烂在心里 提交于 2019-12-11 08:14:43
问题 i'm a beginner in mef and so i have a question :) i have the following: [PartCreationPolicy(CreationPolicy.Shared)] [Export(typeof(SharedExport))] public class SharedExport : INPCBase { [ImportMany(typeof(INonShared),RequiredCreationPolicy = CreationPolicy.NonShared)] private IEnumerable<Lazy<INonShared,Dictionary<string,object>>> fac; ... public void Open() { foreach (var lazy in fac) { this.Muster.Add(lazy.Value); } } the imported classes all marked as nonshared. [PartCreationPolicy

Proper way to expose third party visual control in MEF

回眸只為那壹抹淺笑 提交于 2019-12-11 07:42:05
问题 What is the proper way to do that? Let's say we have some third party library in our project and we need to provide an access to some controls which are sealed. New widgets will be created and added to the application using MEF and they should be able to import some controls from the core application. So how to export those controls properly? 回答1: If you cannot modify the original class (e.g. ThirdPartyComponent ), then you can do the export via a property on another class (e.g.

MEF open generic problems with 4.5

帅比萌擦擦* 提交于 2019-12-11 07:36:02
问题 We were using MEF Contrib open generics support like this: [InheritedExport] interface ITest2<T> { void Execute(); } class TestClass2<T> : ITest2<T> { public void Execute() { Console.WriteLine(); } } class Program { static void Main(string[] args) { var catalog = new AssemblyCatalog(typeof(Program).Assembly); var container = new CompositionContainer(catalog); var test2 = container.GetExportedValues<ITest2<string>>(); } } However, since the installation of .NET Framework 4.5, this code no

How to load/import dll with MEF out of metro app?

三世轮回 提交于 2019-12-11 07:28:35
问题 I've trying to write a extendable metro app using MEF. I got it working with a local extension (inside of the current assembly). Now I want to load a external dll. The DirectoryCatalog seems to be not present in .net 4.5. So I tried to use ApplicationCatalog but I got the following error while calling SatisfyImportsOnce : Assembly.LoadFrom is not supported in AppX. . Here's me code: var catalog = new AssemblyCatalog(GetType().GetTypeInfo().Assembly); ApplicationCatalog catApp = new

Satisfy Imports in custom ExportProvider

泪湿孤枕 提交于 2019-12-11 06:23:48
问题 I'd like to know how I can have Imports in my custom ExportProvider. Here's an example of what I'm trying to do: public class MyExportProvider : ExportProvider { private List<Export> _exports; [Import()] private IConfig _config; public MyExportProvider() base() { _exports = new List<Export>(); } protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition composition) { if (!_exports.Any()) Initialize(); return _exports.Where(x => definition

Problem with MEF - ExportFactory<T> - call Dispose method

蓝咒 提交于 2019-12-11 04:41:27
问题 If possible call dispose method on object which is created with ExportFactory? Factory is here: public interface IViewModelsControler { IChatViewModel CreatChatViewModel(); } [Export(typeof(IViewModelsControler))] public class ViewModelsControler:IViewModelsControler { [Import] public ExportFactory<IChatViewModel> ChatViewFactory { get; set; } public IChatViewModel CreatChatViewModel() { return ChatViewFactory.CreateExport().Value; } } Creation of object: var chatScreen = ViewModelControler

AppDomain.AssemblyResolve doesn't work (as expected) with MEF

陌路散爱 提交于 2019-12-11 04:23:32
问题 I have this error: Runtime error CS0234: The type or namespace name 'StiOracleSource' does not exist in the namespace 'Stimulsoft.Report.Dictionary' I developed (VS 2012) an application that uses MEF (.NET 4.5) to interconnect several binary assemblies loaded from a database. One of its separate plug-in assemblies (implemented as an stand-alone executable) has dependency on a third party DLL (Database adapter) that cannot be included in the main application. When I run the plug-in as a stand

Something like MEF (Managed Extensibility Framework) for .NET Framework 2.0

十年热恋 提交于 2019-12-11 03:33:36
问题 I used MEF in own of my projects and I liked it a lot. It was easy and after figuring our awkward API model, it just worked. Now I need something like that for .NET Framework 2.0. Is there any similar project out there which can work under .NET Framework 2.0? I'm simply looking for adding plug-in support to my project in a simple way. 回答1: Have a look at Mono.Addins AFAIK its built upon .NET 2.0. 回答2: You can try R.SAT 回答3: I know SharpDevelop has a plug-in mechanism. Maybe you could check