Introduction To Managed Extensibility Framework
The Managed Extensibility Framework (MEF) allows developers to provide hooks into their .NET applications for extensions by first and third parties. MEF can be thought of as a general application extension facility. In this Hands-On Lab, you will learn how to define extensibility points for components, perform conditional binding and component creation and import extended assemblies while an application is running.
The Managed Extensibility Framework (MEF) allows developers to provide hooks into their .NET applications for extensions by first and third parties. MEF can be thought of as a general application extension facility.
MEF enables developers to create extensions dynamically, without the extending application or the extension requiring any specific knowledge of the other. This ensures no coupling exists between the two at compile time, enabling applications to be extended at runtime, without the need to recompile. MEF also provides the ability to examine the metadata of an extension assembly before loading the extension into the application -- a much faster approach.
Several key concepts relating to extensibility are covered in this lab:
Extensibility is achieved, primarily, by adding Import attributes at appropriate points in the application and adding corresponding Export attributes to the extensions. Import and Export attributes can be thought of in the same aspect as a supplier and consumer respectively. Export components supply some value; Import components consume that value. Other options for extensibility are open to developers, including completely custom extensibility approaches; however, this lab focuses solely on the primary approach discussed above. Moreover, the components can be imported using the ImportMany attribute, which loads all the components that match the given contract as a collection.
With the release of Silverlight 4, MEF has been included in it, allowing you to extend rich internet applications. This does not imply that MEF can only be used with Silverlight 4; using the version available in codeplex (http://mef.codeplex.com), MEF can be used to compose applications created in Silverlight 3.
In this Hands-On Lab, you will learn how to:
You must have the following items to complete this lab:
All the requisites for this lab are verified using the Configuration Wizard. To make sure that everything is correctly configured, follow these steps:
To perform the setup steps you need to run the scripts in a command window with administrator privileges.
This Hands-On Lab comprises the following exercises:
This Hands-On Lab includes the following starting materials.
Each exercise is accompanied by an End folder containing the resulting solution you should obtain after completing the exercises. You can use this solution as a guide if you need additional help working through the exercises.
Each exercise contains a Visual Basic and a C# version; Inside the End/Begin solution folder, you will find two folders: VB, containing the Visual Basic version of the exercise, and C#, containing the C# version of it.
Estimated time to complete this lab: 30 minutes.