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
3 answers

Get CustomAttributeValue Properties Value as String Array

I want to get the PropertyValue of CustomAtrribute from all Class as String Here is my Custom Attribute inherited from ExportAttribute [JIMSExport("StockGroup","Stock")] This attribute is attached on many class but with different parameters. First…
Kishore Kumar
  • 12,675
  • 27
  • 97
  • 154
1
vote
1 answer

Is NonShared DbContext in MVC a bad practice?

It is an MVC application with Entity Framework Code First for the ORM and MEF as the IoC. If I mark the DbContext with PartCreationPolicy.Shared there is an error saying the object already exists in the container every time I try to perform an…
Vahid
  • 257
  • 4
  • 14
1
vote
2 answers

MefContrib: How to export composition container

I need to call CompositionContainer.GetExportedValue<> in a controller action. I use MefContrib and I need to know how and where should I add the CompositionContainer itself to the catalog so I can import it in my controller. Update Here's the…
Vahid
  • 257
  • 4
  • 14
1
vote
1 answer

List of Visual Studio's Built-In Smart Tags?

I frequently use the Show Smart Tag shortcut in Visual Studio 2010 (Ctrl + Period) when I want to generate using statements, implement interface methods, generate classes, etc. I recently introduced this shortcut to my co-workers, and they love…
Tedderz
  • 587
  • 5
  • 16
1
vote
1 answer

Use MEF to allow only 2 instances at max per application

I am using MEF as an IOC in my application. I found myself stuck in a situation where I need exactly two instance at a time for a class in my application (across all threads). I thought it would be easy just by adding export attribute twice with…
ZafarYousafi
  • 8,640
  • 5
  • 33
  • 39
1
vote
0 answers

MEF composing never end

I’ve a strange problem in my app. I’m using MEF to load Exports from some Dll’s. Which works on my computer and on the most others too. But on some machines the composing won’t work… MEF starts the composing but it never ends and MEF doesn’t throw…
musium
  • 2,942
  • 3
  • 34
  • 67
1
vote
0 answers

MEF imports with metadata not matching any exports

I have been trying to use MEF on a new project and am having some difficulty getting imports to work, which I cannot explain why. I am following the samples on MSDN and elsewhere, but they are not working for me. This is using MEF 4.0 in a .NET 4…
Michael Collins
  • 289
  • 2
  • 13
1
vote
0 answers

Best way to prevent plugins being shared amongst users

We are developing an C# application based on a plugin architecture using MEF. The main application is just a basic framework and it's modularized functionality will be provided by plugins that the user will have to purchase. I don't really want to…
HadleyHope
  • 1,173
  • 1
  • 10
  • 19
1
vote
3 answers

Trying to find Exports in CompositionContainer

I'm using MEF in my WPF application, and I'm not sure if my exports are not making it into the container because of the way I'm exporting them, or because of the way I'm querying the container. Here's my object hierarchy: public interface…
Random
  • 1,896
  • 3
  • 21
  • 33
1
vote
1 answer

MEF Composition Error, Export doesn't work as it should

this is my form which should display the result from my imported class: public partial class Form1 : Form { [Import(typeof(ITests))] public ITests Template; public string texter; public Form1() { …
machie27
  • 137
  • 1
  • 8
1
vote
1 answer

Prism: Nested Regions

I googled a lot but i didn't find an exact answer. I'm using Prism-Mef, i have RegionB which is nested inside RegionA When i declare: IRegion regionB= regionManager.Regions[RegionNames.RegionB]; i got the exception: The region manager does not…
Hussein
  • 945
  • 1
  • 12
  • 30
1
vote
1 answer

How to use IProjectionBuffer in MEF without creating editor instance?

I am trying to create a Visual Studio extension which handles a multi-language content type. Much like some mvc-templates and Django or ASP.NET which a certain part of the code is in another language. I know that I should use Projection and I…
el_shayan
  • 2,735
  • 4
  • 28
  • 42
1
vote
1 answer

Application scoped parts in ASP.NET MVC with MEF

I'm new to MEF and have some trouble figuring it out. I want to create and ASP.NET MVC application that supports several user stores dynamically. I thought I could use MEF for this. I defined the following contract. public interface IUserProvider { …
zu1b
  • 422
  • 5
  • 11
1
vote
1 answer

Loading MEF Exports out of a folder other than the working directory with mono in linux

I am trying to use MEF (The version that is built in mono) for a simple pluginsystem to extend my application. I followed various tutorials that are running well with Microsofts .NET framework under windows, but (same code) failing under…
Markus Ebner
  • 148
  • 9
1
vote
2 answers

MEF and factories, import created object directly

I’ve started working with MEF. In my application I’ve a factory for some Models. My factory has 2 create methods; one takes a name as parameter, the other a type. [Export(typeof(IFactory))] [PartCreationPolicy(CreationPolicy.Shared)] public class…
musium
  • 2,942
  • 3
  • 34
  • 67
1 2 3
99
100