Tuesday, June 10, 2014

Managed Extensibility Framework

Managed Extensibility Framework:
Three core concepts with MEF:
1)      Export(s) : It exposes Contracts and contract like .NET Interface or Class or property
Code:
[Export(typeof(ICache))]
Public class Caching: ICache
{
               Public object Get(string cache_key)
{
               //Caching implementation
}
}
2)      Imports: Used to consume exported instances.
Code:
[Import()]
Private ICache cache;
3)      Catalog: hosts components that need to be composed.
Code:
Public static void Compose(object o)
{
               var container = new CompositionContainer(
                                             new DirectoryCatalog(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
@”bin\MEFBin”)));
                              Var batch = new CompostionBatch();
batch.AddPart(o);
               container.Compose(batch);

}

No comments:

Post a Comment