mef

How to get exported values (MEF) in metro style apps

拟墨画扇 提交于 2019-12-10 21:06:35
问题 I recognized, that MEF is limited for metro style apps. There is no container anymore, so how can I get specific exported values like ILogger logger = container.GetExportedValues<ILogger>(); ? Is the any tutorial available covering the metro version of MEF? Thanks for Help, Eny 回答1: As I already wrote in the comment, I don't really like this approach, but it is the best what I have up to this moment: public class CompositionContainer { private readonly CompositionService _service; public

Removing parts from CompositionContainer using a CompositionBatch object

血红的双手。 提交于 2019-12-10 18:49:55
问题 I have a MEF based solution that has several exported implementations of an interface. What I want to be able to do is have a switch that removes ALL the current parts associated with the interface, and in their place, replace them with just a single implementation. I've been trying to do this with a CompositionBatch object, but it doesn't seem to work. Here's an example of what I'm doing: [Export(typeof(IFoo)] public class Foo1 : IFoo { } [Export(typeof(IFoo)] public class Foo2 : IFoo { } I

MEF: How to manually configure Export for a contract implementation

瘦欲@ 提交于 2019-12-10 18:43:31
问题 I have a MEF's CompositionContainer, a contract (say IFoo) and a module (Prism module but it doesn't matter much here, just some component). I want in my module to register the contract's implementation (FooImpl). If it's Unity I'd do like this: unity.RegisterType<IFoo, FooImpl>(). That's all. With MEF I've puzzled. I have to mark my implementation with ExportAttribute, but that lead to it'll be exported automatically. I want to manage this by myself. Take a look at the code: class MyModule:

Type.GetType returns null when using MEF

删除回忆录丶 提交于 2019-12-10 17:52:50
问题 I'm currently using MEF for a project to import plugins, as the plugins are written in WPF they each have a view and a viewmodel. The plugins know about the viewmodel but the main shell UI will construct the view and bind the viewmodel using a convention over configuration type pattern. I have used some code from the Build-your-own-MVVM-framework sample to do the auto view discovery: [ImportMany(typeof(IPlugin))] public IEnumerable<IPlugin> Plugins { get; set; } var viewTypeName = this

MEF Property Export with PartCreationPolicy

百般思念 提交于 2019-12-10 16:18:00
问题 When I try to do this: [Export(typeof(IMyService))] [PartCreationPolicy(CreationPolicy.Shared)] private MyService Service { get { var service = new MyService(); service.Configure(); return service; } } I get a compile error: Attribute 'PartCreationPolicy' is not valid on this declaration type. It is only valid on 'class' declarations. Is this a bug? I don't see why MEF would allow property exports but not allow one to specify the part lifetime. Using VS2010 RC. 回答1: The PartCreationPolicy

Why am I unable to debug a dynamically loaded assembly?

十年热恋 提交于 2019-12-10 12:34:44
问题 I am working on a Web API project that uses an in-house mocking framework that allows to intercept and modify the responses from the controllers. It uses MEF to loading an assembly that contains code that is executed if some preconditions are matched. I know that this is working properly, because I can see in the response that the mock has been executed, but for some reason I am unable to debug the code in the dynamically loaded assembly. Although breakpoints look active, execution never

How to exchange/replace the shared (singleton) object in MEF container?

若如初见. 提交于 2019-12-10 12:16:23
问题 This may be simple but as I am new to MEF arena that is why I am having some difficulty to figure out the solution to my problem. I am working on an application using WPF + Prism with MEF as DI container. I want to tie my object (i.e. RuleFile ) with each application instance by associating it with the file say RuleFile1.ruleapp. Therefore I have decorated it with attribute [PartCreationPolicy(CreationPolicy.Shared)] to treat it as singleton so that it remains same throughout the application

Passing multiple implementations of the same interface using DI

无人久伴 提交于 2019-12-10 10:51:09
问题 One of our company's products is composed of many small web-applications and a windows service, a.k.a. components, each potentially residing in a different computer. One of them is a WebForms project, which serves as the configuration hub for all the others. We are designing a feature now to expose general information of a component. Imagine a simple interface like this for instance: public interface IStatistics { Statistics GetStatistics(); } We want to use this same interface on all

Prism RegionManager.Region[“”].GetView(“string”) always returns null

纵然是瞬间 提交于 2019-12-10 10:44:39
问题 I have an import in my view model for the regionmanager [Import] private IRegionManager _regionManager; I want to be able to get a view and remove it from a region. First step, get the view i.e. _regionManager.Regions["MainRegion"].GetView("ViewName"); Whatever I do this always returns null. I specify a name for my view when adding it using view injection. When I try to use the above method though it doesn't work. I've seen other posts regarding this matter but none that seem to explain how

Is it possible to parameterize a MEF import?

允我心安 提交于 2019-12-10 09:28:46
问题 I am relatively new to MEF so I don't fully understand the capabilities. I'm trying to achieve something similar to Unity's InjectionMember. Let's say I have a class that imports MEF parts. For the sake of simplicity, let's take the following class as an example of the exported part. [Export] [PartCreationPolicy(CreationPolicy.NonShared)] public class Logger { public string Category { get; set; } public void Write(string text) { } } public class MyViewModel { [Import] public Logger Log { get;