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
367
votes
30 answers

Why do I get a warning icon when I add a reference to an MEF plugin project?

I wish to test the core class of a plugin by directly referencing the plugin project and instantiating the plugin class. When I create a test Console App project and add a project reference to the plugin project, I get a warning icon (yellow…
ProfK
  • 49,207
  • 121
  • 399
  • 775
168
votes
7 answers

Choosing between MEF and MAF (System.AddIn)

The Managed Extensibility Framework (MEF) and Managed AddIn Framework (MAF, aka System.AddIn) seem to accomplish very similar tasks. According to this Stack Overflow question, Is MEF a replacement for System.Addin?, you can even use both at the same…
dthrasher
  • 40,656
  • 34
  • 113
  • 139
80
votes
3 answers

MEF with MVC 4 or 5 - Pluggable Architecture (2014)

I am trying to build a MVC4/MVC5 application with a pluggable architecture like Orchard CMS. So I have a MVC application which will be the startup project and take care of auth, navigation etc. Then there will be multiple modules built separately as…
Yashvit
  • 2,337
  • 3
  • 25
  • 32
71
votes
4 answers

MEF vs. any IoC

Looking at Microsoft's Managed Extensibility Framework (MEF) and various IoC containers (such as Unity), I am failing to see when to use one type of solution over the other. More specifically, it seems like MEF handles most IoC type patterns and…
PureCognition
  • 1,253
  • 2
  • 10
  • 14
67
votes
7 answers

Where can I learn about MEF?

I watched the DNR TV episode with Glenn Block and it looks like MEF would be useful for my company. I am trying to find out more information on it's strengths and weaknesses and some sample projects that use it. Are there any good blogs/tutorials…
Jeffrey Lott
  • 7,171
  • 6
  • 28
  • 28
60
votes
5 answers

Looking for a practical approach to sandboxing .NET plugins

I am looking for a simple and secure way to access plugins from a .NET application. Although I imagine that this is a very common requirement, I am struggling to find anything that meets all my needs: The host application will discover and load its…
Tim Coulter
  • 8,705
  • 11
  • 64
  • 95
56
votes
3 answers

MEF (Managed Extensibility Framework) vs IoC/DI

What problems does MEF (Managed Extensibility Framework) solves that cannot be solved by existing IoC/DI containers?
alex
  • 74,215
  • 9
  • 49
  • 57
54
votes
2 answers

What is different between and purpose of MEF and Unity?

I just start study DI (I'm working on WPF/Silverlight but I have a plan to move to ASP.NET). After I read some DI articles from internet there are two Frameworks that I'm interested in, MEF and Unity. I want to know what is the real-world different…
Anonymous
  • 9,366
  • 22
  • 83
  • 133
49
votes
7 answers

Disadvantages of Lazy?

I recently started using Lazy throughout my application, and I was wondering if there are any obvious negative aspects that I need to take into account when using Lazy? I am trying to utilize Lazy as often as I deem it appropriate, primarily…
eandersson
  • 25,781
  • 8
  • 89
  • 110
47
votes
2 answers

Difference between MEF and IoC containers (like Unity, Autofac, SMap, Ninject, Windsor.Spring.net, etc.)

I have been searching about the dependency injection and read a few articles. But still I am unable to find out the difference between MEF and other IoC's. So, my question is this: In which situation should I prefer to use a MEF or IoC…
44
votes
3 answers

IISExpress crashes with 0xc0000008 error

Occasionally when running my MVC4 site in VS2012 using IISExpress I get the following error and IISExpress stops: iisexpress.exe: Managed (v4.0.30319)' has exited with code -1073741816 (0xc0000008) 'An invalid handle was specified There is nothing…
Jonesie
  • 6,997
  • 10
  • 48
  • 66
43
votes
3 answers

MEF Constructor Injection

I'm trying to figure out MEF's Constructor Injection attribute. I have no idea how I tell it to load the constructor's parameters. This is the property I'm trying to load [ImportMany(typeof(BUsers))] public IEnumerable LoadBUsers { get; set;…
alpha
  • 487
  • 1
  • 6
  • 8
42
votes
2 answers

Visual Studio 2010 addin writing articles/tutorials?

Does anyone know of some good articles / tutorials on writing addins/plugins for Visual Studio 2010?
Simon
  • 33,714
  • 21
  • 133
  • 202
38
votes
6 answers

.NET exception caught is unexpectedly null

See below for an explanation of what is going on I have a really weird issue where the exception caught is null. The code uses MEF and tries hard to report composition errors. Using the debugger I can see the exception being thrown (an…
Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
35
votes
4 answers

MVVM, Unity, Prism, MEF, Caliburn - What should I use?

Please help - I'm getting lost! I'm writing a small desktop application which has some controls and some screen. This should later be integrated with a small web site, also having some screens. The idea is to let the user edit videos and select…
Avi
  • 15,696
  • 9
  • 39
  • 54
1
2 3
99 100