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 Export
ed 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.