Change the Rules


Silverlight 4 – A Guided Tour of MEF
Mike Taulty, Microsoft UK
mtaulty@microsoft.com
mtaulty.com
@mtaulty
MEF – What is it? How and when do I get it?
 • the Managed Extensibility Framework
   – an extensible framework for composing applications
     from a set of loosely-coupled parts discovered and
     evolving at run-time
 • versions
   – .NET Framework shipping with Silverlight 4
   – .NET Framework 4 shipping with VS 2010
   – CodePlex version for Silverlight 3, .NET 3.5 Sp1
“scenario”




             AlbumArtProvider
Change the Rules




demo
using MEF in our scenario
MEF models composable parts
MEF composes parts




     Compose
which parts compose together?




     Contract
     Name
     Shared
     Metadata
                                Contract
                                Name
                                Cardinality
                                Shared
                                Recomposable
                                Metadata
Change the Rules




demo
matching imports to exports
parts & part definitions




  • PartDefinition is a blueprint for a Part
     – similar to Object and Type in .NET
     – but can have Part without PartDefinition
container draws parts from catalogs
or mix in pre-instantiated parts
Change the Rules




demo
the built-in catalogs*
(* one is missing, we’ll come back to it later )
things change - recomposition
recomposition is key for Silverlight



                                       MyApp.xap



                                       Extras.xap
Change the Rules




demo
recomposition & DeploymentCatalog
( completing our story of built-in catalogs )
stable composition

reject parts with unsatisfied imports
Change the Rules




demo
stable composition
MEF and Model View ViewModel
 • Strong separation of concerns possible with
   Silverlight development
   – user interface declared in XAML
   – loosely binds to data
   – functionality invoked by declarative commands
 • Encapsulated by the “MVVM” pattern
               binding




              commands
Change the Rules




demo
MEF and MVVM
Change the Rules


Pointers to more advanced
topics
extensibility – catalogs & export providers
extensibility – programming models

 • Programming models         MEF Primitives
   in MEF are pluggable       ComposablePartCatalog
 • [Attribute] is the
                              ComposablePartDefinition
   built-in model
 • Custom models involve      ComposablePart
   implementing some/all of
   MEF’s primitive classes    ExportDefinition

                              ImportDefinition
resources
 • Channel 9 Silverlight 4 MEF Screencasts
   – channel9.msdn.com/tags/learnMEFSL4
 • Glenn Block
   – blogs.msdn.com/gblock
 • Nicholas Blumhardt
   – blogs.msdn.com/nblumhardt
 • MEF on CodePlex
   – mef.codeplex.com
thank you 




© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it
should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.
MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Change the Rules


Silverlight 4 – A Guided Tour of MEF
Mike Taulty, Microsoft UK
mtaulty@microsoft.com
mtaulty.com
@mtaulty

Mike Taulty DevDays 2010 Silverlight MEF

  • 1.
    Change the Rules Silverlight4 – A Guided Tour of MEF Mike Taulty, Microsoft UK mtaulty@microsoft.com mtaulty.com @mtaulty
  • 2.
    MEF – Whatis it? How and when do I get it? • the Managed Extensibility Framework – an extensible framework for composing applications from a set of loosely-coupled parts discovered and evolving at run-time • versions – .NET Framework shipping with Silverlight 4 – .NET Framework 4 shipping with VS 2010 – CodePlex version for Silverlight 3, .NET 3.5 Sp1
  • 3.
    “scenario” AlbumArtProvider
  • 4.
    Change the Rules demo usingMEF in our scenario
  • 5.
  • 6.
  • 7.
    which parts composetogether? Contract Name Shared Metadata Contract Name Cardinality Shared Recomposable Metadata
  • 8.
  • 9.
    parts & partdefinitions • PartDefinition is a blueprint for a Part – similar to Object and Type in .NET – but can have Part without PartDefinition
  • 10.
    container draws partsfrom catalogs
  • 11.
    or mix inpre-instantiated parts
  • 12.
    Change the Rules demo thebuilt-in catalogs* (* one is missing, we’ll come back to it later )
  • 13.
    things change -recomposition
  • 14.
    recomposition is keyfor Silverlight MyApp.xap Extras.xap
  • 15.
    Change the Rules demo recomposition& DeploymentCatalog ( completing our story of built-in catalogs )
  • 16.
    stable composition reject partswith unsatisfied imports
  • 17.
  • 18.
    MEF and ModelView ViewModel • Strong separation of concerns possible with Silverlight development – user interface declared in XAML – loosely binds to data – functionality invoked by declarative commands • Encapsulated by the “MVVM” pattern binding commands
  • 19.
  • 20.
    Change the Rules Pointersto more advanced topics
  • 21.
    extensibility – catalogs& export providers
  • 22.
    extensibility – programmingmodels • Programming models MEF Primitives in MEF are pluggable ComposablePartCatalog • [Attribute] is the ComposablePartDefinition built-in model • Custom models involve ComposablePart implementing some/all of MEF’s primitive classes ExportDefinition ImportDefinition
  • 23.
    resources • Channel9 Silverlight 4 MEF Screencasts – channel9.msdn.com/tags/learnMEFSL4 • Glenn Block – blogs.msdn.com/gblock • Nicholas Blumhardt – blogs.msdn.com/nblumhardt • MEF on CodePlex – mef.codeplex.com
  • 24.
    thank you  ©2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
  • 25.
    Change the Rules Silverlight4 – A Guided Tour of MEF Mike Taulty, Microsoft UK mtaulty@microsoft.com mtaulty.com @mtaulty