This is a mirror of official site: http://jasper-net.blogspot.com/

Working with AssemblyCatalog in MEF

| Tuesday, August 30, 2011
MEF is a component defined in Base class library for extensibility. If you are really looking for writing something that extend itself at runtime, or that supports plugins to be attached to it, you should give MEF a try. You can read how MEF works from my post here. In this post I will demonstrate how to use AssemblyCatalog in MEF World.

A Catalog is a container that lists Parts where each Part is actually mapped to a Type which individually hosts a number of Exports in forms of ExportDefination and number of Import in forms of ImportDefinations. An AssemblyCatalog is actually a collection of TypeCatalogs where the Types are actually defined within one particular assembly.

Lets take a look at AssemblyCatalog using our previous code :

public class ExportContainer
{
[Export]
public string ExportName { get; set; }

[Export]
public string GetName()
{
return this.ExportName;
}

[Export]
public Action MyActionDelegate { get; set; }

}

Now if I use Assemblycatalog to load the Catalog into Parts we write :

static void Main(string[] args)
{
   AssemblyCatalog catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

   Console.WriteLine(catalog.Parts.Count());

   Console.ReadKey(true);
}


Read more: Daily .Net Tips
QR: https://chart.googleapis.com/chart?chs=80x80&cht=qr&choe=UTF-8&chl=http://dailydotnettips.com/2011/08/30/working-with-assemblycatalog-in-mef/

Posted via email from Jasper-net

0 comments: