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:
{
[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: