
Microsoft Managed Extensibility Framework
On June 4, a Microsoft development team unveiled the Managed Extensibility Framework (MEF) CTP. MEF is a mechanism that allows you to implement extensibility support (for example, plugins) in projects with a minimum of code.
Link to the message from the developers: weblogs.asp.net/whaggard/archive/2008/06/04/first-managed-extensibility-framework-mef-bits-released.aspx
You can download CTP along with examples and documentation here: code.msdn .microsoft.com / mef
I will give a short example from the documentation below for a better understanding of what MEF is.
So what does MEF give? Consider the first example from the project documentation. The first piece of code describes a simple property that affects the title of a button.
Note that this property is marked with the [Import ("ButtonCaption")] attribute. This is, in its way, a mark of where data can be changed through external extensions.
Next, the simplest extension is defined:
As you can see from the code, the data source is defined in the class via [Export ("ButtonCaption")], which indicates that this class can set header values for the button.
In the end, both pieces of code are mixed in order to meet each other:
Link to the message from the developers: weblogs.asp.net/whaggard/archive/2008/06/04/first-managed-extensibility-framework-mef-bits-released.aspx
You can download CTP along with examples and documentation here: code.msdn .microsoft.com / mef
I will give a short example from the documentation below for a better understanding of what MEF is.
So what does MEF give? Consider the first example from the project documentation. The first piece of code describes a simple property that affects the title of a button.
[Import ("ButtonCaption")]
public String ButtonCaption
{
get {return theButton.Content.ToString (); }
set {theButton.Content = value; }
} * This source code was highlighted with Source Code Highlighter .
Note that this property is marked with the [Import ("ButtonCaption")] attribute. This is, in its way, a mark of where data can be changed through external extensions.
Next, the simplest extension is defined:
public class ExampleStringProvider
{
[Export ("ButtonCaption")]
public String providedCaption
{
get {return "MEF Hello World !!"; }
}
} * This source code was highlighted with Source Code Highlighter .
As you can see from the code, the data source is defined in the class via [Export ("ButtonCaption")], which indicates that this class can set header values for the button.
In the end, both pieces of code are mixed in order to meet each other:
public MyHelloWorld ()
{
InitializeComponent ();
CompositionContainer container =
new CompositionContainer ();
container.AddComponent(this);
container.AddComponent (new
ExampleStringProvider ());
container.Bind ();
} * This source code was highlighted with Source Code Highlighter .
This code registers the interconnected components in the composition container and, by calling the Bind method, binds the data from the extension to the existing properties. Alternatively, the ExampleStringProvider extension class can be replaced with another class that provides different functionality, for example, which displays a date instead of text:public class DateStringProvider
{
[Export ("ButtonCaption")]
public String providedCaption
{
get {return DateTime.Today.ToString (); }
}
} * This source code was highlighted with Source Code Highlighter .
As you can see from a simple example, MEF implements a data binding mechanism during code execution through a reflection mechanism. The idea lay on the surface, and I'm glad that Microsoft took care of creating a convenient and powerful library that implements a mechanism for expanding the functionality of the code.