際際滷

際際滷Share a Scribd company logo
Crystal MEF
Software is Hard 
 Components
 Extensibility
 IDTExtensibility2
 ASP.NET Providers
 System.AddIn
Managed Extensibility Framework
 Released under .NET 4.0
 System.ComponentModel.Composition
 Open source
 http://mef.codeplex.com
 DEMOS
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
1. Parts
 A type annotated with MEF metadata
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
3. Import
 [Import(type)] on a property makes it
consume a Part
public class SomeClass
[Import(typeof(Ilogger))
private Ilogger MyLogger()
 [ImportMany()] allows a part to import a
collection (IEnumerable<T>) of parts
4. Composition
 Parts are loaded through Catalogs
 TypeCatalog
 IEnumerable<types>
 [types]
 AssemblyCatalog
 DirectoryCatalog
 Your custom implementation of a catalog e.g.
DatabaseCatalog, DownloadCatalog
遜. Recomposition
 Dynamic composition in response to a change
in the number of available Parts
MEF Help
 No book 
 http://tinyurl.com/stackoverflowmef
 Twitter
 @gblock
 @kathleendollard
 #MEF

More Related Content

Crystal MEF

  • 2. Software is Hard Components Extensibility IDTExtensibility2 ASP.NET Providers System.AddIn
  • 3. Managed Extensibility Framework Released under .NET 4.0 System.ComponentModel.Composition Open source http://mef.codeplex.com DEMOS
  • 4. 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
  • 5. 1. Parts A type annotated with MEF metadata
  • 6. 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
  • 7. 3. Import [Import(type)] on a property makes it consume a Part public class SomeClass [Import(typeof(Ilogger)) private Ilogger MyLogger() [ImportMany()] allows a part to import a collection (IEnumerable<T>) of parts
  • 8. 4. Composition Parts are loaded through Catalogs TypeCatalog IEnumerable<types> [types] AssemblyCatalog DirectoryCatalog Your custom implementation of a catalog e.g. DatabaseCatalog, DownloadCatalog
  • 9. 遜. Recomposition Dynamic composition in response to a change in the number of available Parts
  • 10. MEF Help No book http://tinyurl.com/stackoverflowmef Twitter @gblock @kathleendollard #MEF