Monday, February 8, 2010

The MEF (Managed Extensibility Framework) PART-II

In this Part-II we are going to separate our plug-ins from our main application and we are going to use Directory and Aggregate Catalogs to compose our parts.

Here is the project solution structure  which has  three projects.

1) Contract

2) Text Format Plug-in as separate Assembly.

3) Main Application with HTML Format Plug-in.


Now i am going to create new folder name called Plug-in in our Main Application project. Inside this folder we are going to copy the Text Format Plug-in project output Assembly. Now our Compose able parts are in two different places( Folder, Executing Application). Now we need to Aggregate them. To do we need to re-write the Blog part 1 ComposeParts method .

public void ComposeParts()
AggregateCatalog mergeParts = new AggregateCatalog();

// Get parts from Same Assembly.
var asmcatalog =new AssemblyCatalog((Assembly.GetExecutingAssembly()));

//Get Parts from Directroy
var dirCatalog = new DirectoryCatalog(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Plugin", "*.dll");

var container = new CompositionContainer(mergeParts );


Assembly Catalog shows HTMLBasedFormat  Part=1 


Directory Catalog shows Parts=1


Now the Aggregate Catalogs shows Parts=2.


Next post we will see how we can use MEF in SilverLight Application.



1 comment:

marcorsouza said...

Hello you have to post the code, I am encountering problems in that part of code inside the plugin folder.