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

MEF not importing methods that has attribute which allows multiple

Created MetadataAttribute that allows using multiple. [MetadataAttribute] [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class BusinessLogicMetaDataAttribute : ExportAttribute, IBusinessLogicMetaData { //...... } then…
Dilshod
  • 3,189
  • 3
  • 36
  • 67
1
vote
0 answers

Use prism/mef without MefBootstrapper

I want to use some assemblies containing views and viewmodels exported using prism/mef in some other program. This other program does not contain a custom MefBootstrapper (since it does not use mef). Creating the catalog and container is easy, but…
Sam
  • 28,421
  • 49
  • 167
  • 247
1
vote
1 answer

Can MEF Support Multiple Plug-ins Using Different Interfaces?

I have a need to load one DLL (Data) using one interface (IDataSender) and another DLL (Message) using another interface (IMessageSender). The code below is generating an error that the DLL being loaded doesn’t support the interface from the other…
Sailor
  • 13
  • 2
1
vote
0 answers

MEF and ICommand

i have some problems with commands. For example. I have Workspace with a menu. In menu I importing IMenuItem whitch contain ICommand. So to make it work i have to create a CommandBinding in my Workspace. Now, to import some DataTemplate i'm…
Towelie
  • 99
  • 2
  • 10
1
vote
1 answer

Issue with MEF and Prism : A duplicate module with the name {0} has been found by the Loader

I am trying to create a very basic application using Prism, MEF and WPF. I have a WPF application project which has a Shell.xaml and Bootstrapper. Code for BootStrapper is below: public class SimpleMefApplicationBootstrapper : MefBootstrapper { …
user728630
  • 2,025
  • 5
  • 22
  • 35
1
vote
1 answer

ASP.NET MVC With MEF integration

I am following the same approach used in this link in my ASP.NET MVC 2 project and it is working fine. All my pages are partial views (ascx). So I have created a class library in my solution as a plugin the same way done in the link sample and put a…
HEH
  • 305
  • 6
  • 15
1
vote
0 answers

Using RegisterViewWithRegion with derived usercontrol

I am writing an application with WPF using Prism and the Managed Extensibility Framework. The purpose is to allow developers to create there own 3rd party modules. To remove as much work as possible I have created some base classes in a Common…
1
vote
0 answers

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

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…
Arlen Keshabyan
  • 107
  • 2
  • 8
1
vote
1 answer

Composition choosing implementation

If I have multiple implementations of same interface [Export("DALREMOTE", typeof(IDAL))] [PartCreationPolicy(CreationPolicy.Shared)] public class DAL : IDAL and [Export("DALLOCAL", typeof(IDAL))] [PartCreationPolicy(CreationPolicy.Shared)] public…
klashagelqvist
  • 1,251
  • 2
  • 26
  • 52
1
vote
0 answers

how to register an instance of object with ASP.NET MVC and MEF?

We are building an ASP.NET MVC 4 application and taking advantage of MEF Lightweight Composition. It works great for everything we have so far. But we would like to create a couple of parts manually at start-up and add them to the container. This is…
Eric Liprandi
  • 5,324
  • 2
  • 49
  • 68
1
vote
0 answers

mef Import always null

when I'm trying to import some service that gets some data from db the dataprovider import is always null ( Object reference not set to an instance of an object). I had a look into the aggregatecatalog and the Assembly which contains Service seems…
nukleos
  • 419
  • 2
  • 8
  • 19
1
vote
1 answer

Cannot load an assembly via MEF due to missing another assembly

Issue: I have two projects. The first named Studio and the second named Worker which is a class library. Worker project refers some third party assemblies like Ecng.Common, Ecng.Data, etc. When i try to load Worker in Studio via MEF, MEF throws an…
Vader
  • 21
  • 3
1
vote
0 answers

Can ExportFactoryProvider be used in a Winforms project? (mef)

I would like to instantiate multiple instances of multiple plugins that implement a single interface within my application and from the research I've done it requires the usage of an ExportFactoryProvider. I am using .Net 4.5 and thought support for…
offthat
  • 400
  • 2
  • 10
1
vote
1 answer

MEF inject container

I`m building a simple app using MEF to better understand it, and I'm facing a problem. The app is a simple calculator that you can create new operations. Each operation is a class that exports IOperation. Here's the ADD operation…
Leonardo
  • 10,737
  • 10
  • 62
  • 155
1
vote
1 answer

List of DisposableLazy`2 does not have 'Add' method when called using dynamic variable

Problem I am facing a problem using dynamically created list of items when Add method is called on dynamicvariable. Consider following code. IEnumerable plugins = (IEnumerable)field.GetValue(instance); if (plugins == null) …
Lukáš Rubeš
  • 163
  • 1
  • 9