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

How to setup a class to load on start up in my WPF shell application, without calling inside Application Start up method

I have Prism Shell application, There is class which primarily focused execuing method on subscribed events. These events are fired from a separate module in my solution. My class is ApplicationMenuSubscriber which is in my shell application. My…
kuhajeyan
  • 10,727
  • 10
  • 46
  • 71
1
vote
1 answer

navigation in not working when [PartCreationPolicy(CreationPolicy.Shared)] in prism

In my prism application I want to make a single shared instance of a view. When I try to navigate the first time it works fine, but when I try to second time it's not working. If I change the PartCreationPolicy from Shared to NonShared it works but…
Sanjay Patel
  • 955
  • 1
  • 8
  • 22
1
vote
2 answers

C#: MEF Exporting Properties

I am trying to get the Exported Properties in my defined classes, but I think something is missing that I don't know of. Here is my Handler class: public class Handler { public string Message { get; private set; } public void Create(string…
aminjam
  • 646
  • 9
  • 25
1
vote
0 answers

Event Triggering from MEF plugin C# WPF

I would like to know how I can trigger event or call any specific function from MEF plugin to/in host application, and I would really appreciate it if you could provide any guideline for this. Actually I was implementing C# WPF application with…
1
vote
1 answer

ASP.NET WebApi Controllers in the external dll using MEF

I have simple ApiController in the separate project: Public Class CustomController Inherits ApiController Public Function GetSomething() As…
Algis
  • 612
  • 1
  • 8
  • 23
1
vote
1 answer

Compose parts, even if one export fails

I have the problem that I want to import types from a module dictionary. But because of the plugin based modularity some imports may fail. But if only one import fails, nothing gets imported - which is certainly not wanted. try { // Use the…
BitKFu
  • 3,649
  • 3
  • 28
  • 43
1
vote
1 answer

System.Security.SecurityException when creating a new FileStream

I have a regular .NET application. In this case I have a part that's being imported by MEF. It imports fine, but at a certain point, I want to save a List of objects to a file. In this case it's just saving a list of high scores: class…
Scott Whitlock
  • 13,739
  • 7
  • 65
  • 114
1
vote
1 answer

How do I add a header to a MEF call

I have a silverlight application where I download xaps using MEF. I would like to put a authorization token in the header of the call so that not anyone will be able to reach the xaps. Something like this: catalog = new…
user438236
  • 357
  • 3
  • 9
1
vote
0 answers

What is the best way to load/save a configuration (potentially from disk) for a plugin in MEF?

I'm building a plugin system for an emulator with MEF and now I'm trying to resolve an issue with loading and saving plugin settings, I've read this post Populate MEF plugin with config data but I dont see a clear example. To sum up, my main doubt…
AlFranco
  • 11
  • 2
1
vote
0 answers

Generic out of work when Use RegistrationBuilder IN MEF

I would like to just use RegistrationBuilder to create parts. example: public interface IModel { String Name { get; } } public interface IRepository { } class ModelOne : IModel { public String Name { get { return "ModelOne"; } } } class…
1
vote
4 answers

Invoke Func<> with parameters

I am importing methods with MEF. I call this method to get all exported methods: var methods = container.GetExports,MyMetadata>("contract name"); NOTE: Sometimes Func changes. For example it might have more…
wpf_starter
  • 67
  • 3
  • 11
1
vote
1 answer

MEF: [Import] Null Reference

I'm using Caliburn.Micro with MEF in one of my projects. I can get imports in the root viewmodel. But if I want to get imports into some other classes, it will not work. For example: [Export] public class A { [Import] static ILogger…
Isilmë O.
  • 1,668
  • 3
  • 23
  • 35
1
vote
0 answers

Navigation fails in Silverlight application using MEF

I have a Silverlight application using MEF to load UserControl plugins into the main shell. Each plugin has a metadata in which described are the name, version, icon and something like these of the plugin and I use [ImportMany] attribute to import…
Isilmë O.
  • 1,668
  • 3
  • 23
  • 35
1
vote
2 answers

mvc 4 mef import/export confusion

I'm having a difficult time wrapping my head around Mef and how imports and exports work. My project structure is as follows. Projects: MefMVPApp (Main MVC 4 app) MefMVCFramework.Common(Interfaces shared between the…
KC.
  • 87
  • 12
1
vote
1 answer

.Net equivalent to deployable EAR

In one of our Java EE environments we are able to encapsulate modules inside of java ear files and deploy them to our JBoss environment so that they will be picked up and made available to users. In the .Net world how would one go about…
scarpacci
  • 8,957
  • 16
  • 79
  • 144
1 2 3
99
100