Exercise 1: Using MEF to Extend an Application
One practical use of the Managed Extensibility Framework is adding modules to an application at runtime. This is useful in a scenario in which users chooses specific modules to purchase or install originally and may add more modules at a later time. Using MEF, you can configure your application to monitor a well-known directory and add any module assemblies found in that directory. Dropping module assemblies into a directory allows your application to load those assemblies without explicitly setting references to them.
Task 1 – Updating Your Application to Load Composable Parts
In this task, you will modify an existing WPF Window class to create extension hooks that will allow dynamically importing queries. You will update this query classes later in this exercise.
Task 2 – Updating Your Composable Part to Export Contracts
In this task, you will modify an existing Windows Class Library project with services classes to query a collection of cars. You will use MEF to mark the queries to export a contract to another application.
Task 3 – Creating a New Extension
In this task, you will create a new application extension with a query services class. You will use MEF to Export contracts and a build action to avoid references between projects. Additionally, you can mix CLR languages and create the new project in different CLR language than your main application.