crystal mef
TRANSCRIPT
![Page 1: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/1.jpg)
Crystal MEF
![Page 2: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/2.jpg)
Software is Hard
• Components• Extensibility– IDTExtensibility2– ASP.NET Providers– System.AddIn
![Page 3: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/3.jpg)
Managed Extensibility Framework
• Released under .NET 4.0– System.ComponentModel.Composition
• Open source– http://mef.codeplex.com
• DEMOS
![Page 4: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/4.jpg)
4(½) Key Concepts
• Parts– A component that does something
• Export– Parts that are available to be consumed
• Import– Parts that a program consumes
• Composition– The process by which Imports and Exports are
mated together
![Page 5: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/5.jpg)
1. Parts
• A type annotated with MEF metadata
![Page 6: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/6.jpg)
2. Export
• [Export] on a class exposes it as a Part[Export]public class Logger()
… • [Export(type)] can expose a specific type e.g.
an interface[Export(typeof(ILogger)public class Logger :Ilogger
• [Export(string)] can expose a named contract
![Page 7: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/7.jpg)
3. Import
• [Import(type)] on a property makes it consume a Partpublic class SomeClass
[Import(typeof(Ilogger))private Ilogger MyLogger()
• [ImportMany()] allows a part to import a collection (IEnumerable<T>) of parts
![Page 8: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/8.jpg)
4. Composition
• Parts are loaded through Catalogs– TypeCatalog• IEnumerable<types>• [types]
– AssemblyCatalog– DirectoryCatalog– Your custom implementation of a catalog e.g.
DatabaseCatalog, DownloadCatalog
![Page 9: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/9.jpg)
½. Recomposition
• Dynamic composition in response to a change in the number of available Parts
![Page 10: Crystal MEF](https://reader036.vdocument.in/reader036/viewer/2022082920/55496c02b4c90595518b4f02/html5/thumbnails/10.jpg)
MEF Help
• No book
• http://tinyurl.com/stackoverflowmef
• Twitter– @gblock– @kathleendollard– #MEF