Questions tagged [mef]

The Managed Extensibility Framework (MEF) simplifies the design of extensible and modular applications, and is a standard component of Microsoft .NET 4.0 and Silverlight 4.0

MEF provides mechanisms for discovery and composition of modular component parts allowing a simple extension mechanism for .NET 4.0/Silverlight 4.0 applications. Through the use of the ExportProvider abstraction, MEF has the ability to easily discover and manage instances of your Exported types which easily allows you to bind to various extension points within your application.

Hello World Sample Using the default Attributed Programming Model, MEF allows you to decorate your target types with attributes which define contract definitions for how the part is composed. E.g.

public interface IMessage
{
  void Display();
}

[Export(typeof(IMessage))]
public class HelloWorldMessage : IMessage
{
  public void Display()
  {
    Console.WriteLine("Hello World");
  }
}

With that simple implementation, I am providing a an export definition of my HelloWorldMessage part, which I can use to compose my consumer:

public class Display
{
  [Import]
  public IMessage Message { get; set; }

  public void Display()
  {
    Message.Display();
  }
}

Using interfaces (contracts) this way allows me to maintain a decoupled implementation.

Make sure you visit the MEF CodePlex site for more detailed information works, and ensure you search Stack Overflow for possible answers before you post questions.

2226 questions
12
votes
1 answer

Extensible WPF application - MEF, MAF or simple loading?

(I know about the other MEF/MAF questions but this is a more specific problem) I want to create a WPF application that will basically be just a simple add-in host, GUI and settings. All of the actual work will be done by one or more plugin(s). They…
lacop
  • 2,024
  • 4
  • 22
  • 36
12
votes
3 answers

MEF and ShadowCopying DLLs so that I can overwrite them at runtime

I am trying to stop my application locking DLLs in my MEF plugin directory so that I can overwrite the assemblies at runtime (note I'm not actually trying to have MEF reload them on the fly, at the next app start is fine, i just dont want to have to…
undefined
  • 33,537
  • 22
  • 129
  • 198
12
votes
2 answers

Getting an export from an MEF container given only a Type instance

I have a scenario where I have to get an export from my CompositionContainer instance but I only have a Type to work with; I don't know the type at compile time, hence I can't retrieve the exported object in the normal generic way. Normally you…
Nathan Ridley
  • 33,766
  • 35
  • 123
  • 197
11
votes
6 answers

Creating multiple instances of Imported MEF parts

Currently my WPF application imports a part like this [Import(typeof(ILedPanel)] public ILedPanel Panel { get; set; } But this gives ma a single intance of the class that implements ILedPanel. What I really want to do is have the ability to create…
TimothyP
  • 21,178
  • 26
  • 94
  • 142
11
votes
1 answer

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

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…
11
votes
4 answers

MEF loading plugins from a network shared folder

Tearing my hair out trying to work out why Im having this problem so hope someone can help. I have a program that uses MEF to load plugins. I would like the client and server part of the system to be able to use the same plugin store that will be…
user589195
  • 4,180
  • 13
  • 53
  • 81
11
votes
2 answers

What is included in MEF 2?

I see work is still going on with new features on MEF (MEF Codeplex site) and they are shipping MEF 2 beta releases, however they do not have any decent documentation on what the new features are experimenting/exploring/building? So, what are the…
Robert MacLean
  • 38,975
  • 25
  • 98
  • 152
11
votes
2 answers

MEF Dependencies and versioning

I have a system that uses MEF to load parts. Each of these parts rely on a core library. When I build the project, I add a version number to the .dll files like this: part1-1.0.0.0.dll part2-1.0.0.0.dll Also, there is an application that performs…
Lance Fisher
  • 25,684
  • 22
  • 96
  • 122
11
votes
2 answers

MEF with ImportMany and ExportMetadata

I've just started playing around with Managed Extensibility framework. I've got a class that's exported and a import statement: [Export(typeof(IMapViewModel))] [ExportMetadata("ID",1)] public class MapViewModel : ViewModelBase, IMapViewModel { } …
Furnes
  • 382
  • 1
  • 2
  • 19
11
votes
2 answers

MEF Parts not found for deployed app, but found in Debug mode

I checked a lot of MEF questions here but I can't imagine what my problem is. Here's what's happening: I have a desktop WPF app that I'm deploying with AdvancedInstaller. I use .NET 4.0 and MEF to compose parts. Some parts are in the main project,…
Hannish
  • 1,482
  • 1
  • 21
  • 33
11
votes
1 answer

MEF support on Xamarin.iOS

I am wanting to port a C# Mobile App for Windows 8 tablets using Xamarin. One of the issues we foresee is the use of MEF. Does Xamarin.iOS support MEF?
JLott
  • 1,818
  • 3
  • 35
  • 56
11
votes
2 answers

CompositionContractMismatchException when trying to use MEF with MVC controller

I'm working on a bigger C# MVC 4 project which is divided in several assemblies (Core, Domain, Backend MVC, Frontend MVC etc.). I use the plugin architecture provided by MEF to load and resolve most dependencies. Now I also wanted it to use to load…
Andreas
  • 2,252
  • 1
  • 19
  • 29
11
votes
1 answer

Best Practices for Composed ASP.NET MVC Web Applications (MEF, Areas, DI)

I am currently figuring out how to restructure the architecture of an existing not very modular ASP.NET MVC 3.0 application. I have a plugin like structure in mind to make the existing project extensible. I have searched for different strategies to…
10
votes
2 answers

MEF: Passing different constructor parameters to a part when using CreationPolicy.NonShared

I know there have been lot of questions regarding constructor parameter injection using MEF, but mine is a bit different. I want to know that is there any way to pass different parameter values to the constructor of a part when I am using the…
Yogesh
  • 14,498
  • 6
  • 44
  • 69
10
votes
2 answers

C# Singleton Pattern and MEF

I have a question about the Singleton Pattern and MEF. I'm new in implementing MEF Plugins and I haven't found an answer. Is it possible to provide only one instance of a class through a MEF implemented Plugin? My old class is something like…
subprime
  • 1,217
  • 8
  • 20
  • 34