4. WHAT IS MEF
A library for creating lightweight, extensible applications.
Discover and use extensions with no configuration required.
Easily encapsulate code.
Avoid fragile hard dependencies.
12. HOW TO USE
Step3: Compose Import & Export
Step2: Decorate ExportAttribute
Step1: Decorate ImportAttribute
13. COMPOSE PARTS
private void Compose()
{
var catalog = new TypeCatalog(this.GetType());
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
14. COMPOSE PARTS
private void Compose()
{
var
catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecu
tingAssembly());
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
15. COMPOSE PARTS
private void Compose()
{
var catalog = new DirectoryCatalog(Environment.CurrentDirectory,
"*.dll");
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
16. COMPOSE PARTS
private void Compose()
{
var catalog = new ApplicationCatalog();
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
17. COMPOSE PARTS
private void Compose()
{
var
assemblyCatalog = new AssemblyCatalog(System.Reflection.Assembly.GetEx
ecutingAssembly());
var directoryCatalog = new DirectoryCatalog(Environment.CurrentDirectory,
"*.dll");
var catalog = new AggregateCatalog (assemblyCatalog, directoryCatalog);
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}