Show Menu
Cheatography

Microsoft Extensibility Framework Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Export

Export type
[Export(typeof(IOperation))]
class A : IOperation { }
Export type hierarchy
[InheritedExport(typeof(IOperation))]
class A : IOperation { }
class B : A { }
Export specific contract (category)
[Expor­t("M­yCo­ntr­act­", typeof(IOperation))]
class A : IOperation { }

Import

0..1
[Impor­t(A­llo­wDe­fault = true)]
IOperation operation;
1..1
[Import]
IOperation operation;
0..*
[ImportMany]
IEnumerable<Lazy<IOperation, IOpera­tio­nMe­tad­ata­>> operat­ions;
Import specific contract
[Import("MyContract")]
IOperation operation;
The import attributes work on class fields.
For the ImportMany attribute to work, the type of the field must be a collection type.
 

Catalogs

Aggreg­ate­Catalog
Combines multiple catalogs.
Applic­ati­onC­atalog
Discovers attributed parts in the dynamic link library (DLL) and EXE files in an applic­ation's directory and path.
Assemb­lyC­atalog
Discovers attributed parts in a managed code assembly.
Direct­ory­Catalog
Discovers attributed parts in the assemblies in a specified directory. Use the overload with two parameters to narrow down DLLs and EXEs.
Filter­edC­atalog
Represents a catalog after a filter function is applied to it.
TypeCa­talog
Discovers attributed parts from a collection of types.
Boiler­plate code for using 0..n catalogs:
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(otherCatalog);
var container = new Compos­iti­onC­ont­ain­er(­cat­alog);