• Feed RSS

Pages

0
MEF stands for Managed Extensibility Framework. It is now included in .Net 4.0.

Here I show you a simplest example to create a plugin to load modules dynamically.

Step 1. Design your interface. For example:

Step 2. Implement the interface, and "export" the class.
a. Add reference to System.ComponentModel.Composition
b. Add using System.ComponentModel.Composition;
c. Create a class that implement the interface and add Export attribute. For example:

Step 3. "Import" the class.
a. Create a Catalog. Since plug-ins usually implemented as separate DLLs, let's use DirectoryCatalog for this case.
b. Create the CompositionContainer with the catalog.
c. Use ImportMany to import a list of the classes.
d. Do ComposeParts() for the class you want to import the plugins.
e. In case, some user dropped in a new DLL, you can do Catalog.Refresh() to refresh the list of plugins.
For example:

It's simple. Isn't it?
Today, I am experimenting adding syntax highlighting to Blogger.

First, following instruction in this page to add SyntaxHighlighter script to your blogger template.

Next, you can start editing your blog.

Remember to use <textarea> instead of <pre>, because <textarea> can handle < and > signs in your code (like HTML, or generic types in C# or Java).

Also, customize your tag, whether to show gutter, or control.

Finally, I prefer to use this tag in my blog:

<textarea name="code" class="c#:nocontrols:nogutter">

For example: