The simplest way to see what MEF can do is to build a simple MEF application. In this example, you build a very simple calculator named SimpleCalculator. The goal of SimpleCalculator is to create a console application that accepts basic arithmetic commands, in the form "5+3" or "6-2", and returns the correct answers. Using MEF, you will be able to add new operators without changing the application code.

 Note

The purpose of SimpleCalculator is to demonstrate the concepts and syntax of MEF, rather than to necessarily provide a realistic scenario for its use. Many of the applications that would benefit most from the power of MEF are more complex than SimpleCalculator. For more extensive examples, see Managed Extensibility Framework samples.

Compile and Run

To compile and run this project, you will need to specify the path to the Extensions folder.

1. Open the main code file (Module1.vb or Program.cs).

2. In the constructor, specify the path to the Extensions folder on your local computer.

     catalog.Catalogs.Add(New DirectoryCatalog("C:\\Users\\SomeUser\\Documents\\Visual Studio 2010\\Projects\\SimpleCalculator2\\SimpleCalculator2\\Extensions"))

 

Test The Sample 

To test this project, perform the following steps:

1. Run the project.

     A command window appears.

2. Type addition or subtraction commands.

     1+1

     1-2

3. Try to type multiplication or division commands.

     1*2

     1/2

   The following message is displayed.

     Operation not found!