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
1
vote
2 answers

Can i recreate a CompositionContainer?

i have a wpf application with login window before displaying the mainwindow. i use mef to load all modules/parts. before the mainwindow start i check the user login data against the parts which i display then. the parts a Shared and…
blindmeis
  • 22,175
  • 7
  • 55
  • 74
1
vote
2 answers

MEF and PlugIn properties updates

I'm new to MEF and started a project to test it. What I'm trying to do is opening a MainForm that would load plugins based on an Interface. Those plugins need to be able to exchange information between them and the MainForm should be able to…
Chris
  • 21
  • 4
1
vote
1 answer

Sharing a virtual method implementation

The example code is much simplified. The gist is, we have a project that uses MEF extensively. Every MEF based interface implements IPlugin: public interface IPlugin { ImplementationName ImplementationName {get;} bool TryProvide(FeatureName…
bielawski
  • 1,466
  • 15
  • 20
1
vote
1 answer

MEF + Unity Integration error in MVC4 application

I am creating a Microsft MVC4 app with MEF and Unity integration to handle a plugin architecture (other MVC4 projects) and their dependancies. However I'm receiving an error when attemping to select an MEF imported controller that contains a Unity…
Eaphis
  • 53
  • 1
  • 6
1
vote
2 answers

how to create an instance of a class of another module without adding reference using prism in wpf

I am working on WPF application using Prism 4.0 and MEF. I want to create an instance of class A of Module A in Class B of Module B and want to access properties and methods of Class A without adding any reference of Module A in Module B. I know…
1
vote
1 answer

Load Individual Add-in with MEF

I am trying to load an individual add-in using MEF. My scenario is as follows: when my application starts, it will search for a set of add-ins and load them into my app. After this start-up phase, I would like the user to be able to load an add-in…
Chris Spicer
  • 2,144
  • 1
  • 13
  • 22
1
vote
1 answer

How do I expose module capabilities in an MEF based modular application?

I'm building a small, simple (for now) modular application, based on guidance from the Create composite modular UI application in WPF using MEF and PRISM article. So far I have a main Window, with two Regions, a Bootstrapper class, and two module…
ProfK
  • 49,207
  • 121
  • 399
  • 775
1
vote
1 answer

Sharing methods imported using MEF in WCF client service

I am using the following code to successfully load a plugin in my WCF client service main class: [Import] public IBasePluginService PluginService { get; set; } public void PluginCompose(string targetPath) { var catalog =…
1
vote
1 answer

Caliburn.Micro HelloScreens sample - using Ninject as IOC container

Love the Caliburn.Micro HelloScreens example, but am getting stuck with MEFs Dependency Injection. I would prefer to use Ninject as I am most familiar with it. Have read some great articles on hosting MEF in an IOC container…
faldeland
  • 587
  • 6
  • 20
1
vote
1 answer

How to use Microsoft Composition for attributeless IoC in MVC 4

Microsoft has distributed a NuGet package named "Microsoft Composition (MEF 2)" allegedly to ease MEF setup for web and Windows 8 applications. There is also a Getting started tutorial which provides a somehow vague explanation on how to make use…
Vahid
  • 257
  • 4
  • 14
1
vote
1 answer

Reference MergedDictionary from MEF loaded

I have a problem when loading an external plugin that makes use of a resource dictionary. I am using MEF and lazy loading for loading a user control in an external assembly, which is a User control library project. This user control references a…
1
vote
3 answers

Managing Dependencies of Reflected Dependencies

I presently work with a large solution, containing about 100 projects. At least 10 of the projects are executable applications. Some of the library projects are imported as plugins via MEF and reflection rather than with direct references. If a…
UtopiaLtd
  • 2,520
  • 1
  • 30
  • 46
1
vote
1 answer

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

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…
Matt
  • 7,004
  • 11
  • 71
  • 117
1
vote
1 answer

What should I use for a WCF modular design?

Our application is an enterprise application deployed in a distributed environment. It's an ASP.NET MVC 2.0 project connected to a WCF project on another server. What we need is to make our business modules reusable and testable. So what is the best…
HEH
  • 305
  • 6
  • 15
1
vote
1 answer

Copy library projects to subfolder instead of root when building

I have the following project structure Main Application (exe) Plugin Interface (dll) Plugin A (dll) Plugin B (dll) The Main Application references the Plugin Interface. Plugin Interface has no references. Plugin A and Plugin B reference the Plugin…
metacircle
  • 2,438
  • 4
  • 25
  • 39