Tuesday, January 5, 2010

New features in Silverlight 4 Beta: Managed Extensibility Framework (MEF)

The Managed Extensibility Framework (MEF) is a new library in Silverlight 4. MEF enables you to build modularized applications whose components can be added in an incrementally. MEF ships as part of Silverlight 4, but we’ve also made a Silverlight 3 compatible version of MEF available on codeplex at MEF.Codeplex.com (current version: Preview 8). Read this post!

I have create my sample application (VS solution: MEF). There’ are  excellent showcasts prepared by Mike Taulty. They show many MEF features. I have make VS solution (MEF2) with almost all presented cases.

MEF  features in these 2 solutions:

  • Exports ([Export])
    • Composable Part, properties, methods (as delegates)
    • Export metadata ([ExportMetadata(key, value)])
    • Custom Export Attributes ([Custom]: [Export])
    • Inheritance ([InheritedExport])
    • Life time (option: [PartCreationPolicy]:  Any, Shared, Nonshared)
  • Imports ([Import])
    • Properties, constructor parameters ([ImportingConstructor]), fields, collections ([ImportMany]),  methods (as delegates)
    • Parameter imports (Implied import  - type of parameter (by default),  Explicit import - contract)
    • Importing Metadata
    • Requirement ([Import] option:  AllowDefault)
    • Recomposition (option: AllowRecomposition)
    • Notifications (IPartImportsSatisfactionNotification)
    • Rejection (Stable Composition)
    • Lazy imports (Lazy<T>)
    • Dynamic Instantiation (PartCreator<T>)
  • Composition & hosting
    • Part Initializer (PartInitializer.SatisfyImports)
    • Catalogs (AssemblyCatalog, .NET: DirectoryCatalog / Silverlight: PackageCatalog, TypeCatalog, AggregateCatalog)
    • Containers (CompositionContainer, CompositionHost.InitializeContainer)
    • Export Providers (CatalogExportProvider, AggregateExportProvider)
  • Silverlight 4 Beta Toolkit: Dynamic XAP downloading (PackageCatalog, Package.DownloadPackageAsync)

MEF_01SMEF_02S

On the Internet there are many interesting samples with MEF and Silverlight 3 or 4 Beta. For example:

HauseSpacePlanner (PDC 09)

MEF_03 MEF_04

ExtensibleGrid (Sample in MEF sources, PDC 09)

MEF_05A MEF_05MEF_06

Silverlight 3 Navigation with MEF (Brad Abrams)

MEF_07 MEF_08

Useful links

No comments: