MEF steps• Create a catalog (or collection of catalogs) var catalog = new AggregateCatalog(new DirectoryCatalog(@"."),new AssemblyCatalog(Assembly.GetExecutingAssembly()));• Add catalog(s) to container var container = new CompositionContainer(catalog);• Get a type from the container var window = container.GetExportedValue<CashMaker>();
Filtering• Catalogs can be ﬁltered down using a FilteredCatalog* (* source code available here: http://bit.ly/ MEFFilter)
Lifetime• Export providers can decide on the lifetime of their parts: • Shared: only one instance per container • NonShared: each export will create a new instance • Any: allows any use (can be deﬁned on import)
MEF is:• A framework for creating extensible applications• Puts focus on discovery of parts at run time• as such...
MEF is not• IoC • Inversion of Control is about knowing what dependancies satisfy given classes and allowing the class to hand this requirement off • IoC containers are great at saying => “When asking for an IDependancy you should get Dependancy” • MEF doesn’t have a way of doing this • MEF says I have all these objects and you want some of them... HERE.
Did I say I’m running a Web Dev Conference? http://wdcnz.com