SlideShare uma empresa Scribd logo
1 de 24
Intro to MEF with Silverlight




                            Jeremy Likness
                            Project Manager, Senior Consultant
                            jlikness@wintellect.com
                                                                   Copyright © 2011




consulting   training   design   debugging                       wintellect.com
what we do
    consulting     training    design     debugging

 who we are
   Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins –
   we pull out all the stops to help our customers achieve their goals through advanced
   software-based consulting and training solutions.

 how we do it                                           Training
                                                        •   On-site instructor-led training
   Consulting & Debugging                               •   Virtual instructor-led training
   •   Architecture, analysis, and design services      •   Devscovery conferences
   •   Full lifecycle custom software development
   •   Content creation                                 Design
   •   Project management                               •   User Experience Design
   •   Debugging & performance tuning                   •   Visual & Content Design
                                                        •   Video & Animation Production


consulting    training    design     debugging                                   wintellect.com
Agenda

 • Why MEF?
 • Discovery
 • Lifetime Management
 • Extensibility
 • Metadata
 • 10 Practical Reasons to use MEF
consulting   training   design   debugging   wintellect.com
Why MEF?

 • Misconception: Managed Extensibility
   Framework
 • Part of the framework
 • Discovery
 • Lifetime management
 • Extensibility
 • Metadata


consulting   training   design   debugging   wintellect.com
Welcome to the MEF Lab!

 • I admit I am a MEF addict!
 • You may be surprised by who has done
   MEF
 • Visual Studio 2010
 • 2010 Vancouver Olympics
 • Microsoft (Looking Glass)
 • SharePoint


consulting   training   design   debugging   wintellect.com
Discovery

 • Import: Contract and Demand
 • Export: Implementation and Supply
                        Look Ma! I
 • Part: Supply & Demand need 500
                      don’t
                                           constructor
                                            overloads!
                                 “I need something that implements IMessage”
 [Import]
 public IMessage MyMessenger { get; set; }

 [Export(typeof(IMessage))]
 public class SpecificMessenger : IMessage

                                     “I have something that implements IMessage”


consulting   training   design   debugging                            wintellect.com
Discovery: Catalogs

 •   Catalogs tell MEF where to find parts
 •   AssemblyCatalog: Current assembly
 •   TypeCatalog: List of types
 •   DeploymentCatalog: Silverlight XAP file
 •   AggregateCatalog: Composed of Multiple
     Catalogs



consulting   training   design   debugging   wintellect.com
Discovery: Container

 • The Container wraps the Catalog
 • The Container is responsible for
   Composition:
      – What parts exist?
         • What imports exist for a part?
         • What exports exist for a part?
 • This is the Discovery step
 • In Silverlight specifically the
   “CompositionInitializer” handles containers
consulting   training   design   debugging   wintellect.com
Discovery: Catalogs & Containers

                                                     Wraps parts in the current XAP


                                    Look Ma! No
 var deploymentCatalog = new DeploymentCatalog();

 var container = new
                                   Bootstrapper!
                             CompositionContainer(deploymentCatalog);

 container.ComposeParts(this);

                                      Using the parts in the container, find all
                                       parts in the current class, then satisfy
                                      all imports with corresponding exports
                                                  (“Composition”)



consulting   training   design   debugging                               wintellect.com
Demo
   Hello, MEF!




consulting   training   design   debugging   wintellect.com
CompositionInitializer
 • Notice that composition happens “explicitly” with
   the composition call
 • What about XAML objects? These are created by
   the XAML parser, not MEF
 • How do you share a container across the
   application?
 • CompositionInitializer solves this problem by
   creating a default, global container
 • Must be high level: classes that use this cannot
   export themselves!
consulting   training   design   debugging   wintellect.com
Stable Composition

 •   Guarantees imports are satisfied
 •   Works throughout the entire hierarchy
 •   Helps keep plug-ins “honest”
 •   What about multiple plug-ins?




consulting   training   design   debugging   wintellect.com
ImportMany

 • Allows multiple implementations
 • Stable composition will reject invalid
   exports




consulting   training   design   debugging   wintellect.com
Demo
   ImportMany




consulting   training   design   debugging   wintellect.com
Lifetime Management

 • What’s wrong with Singletons?
      – Change the behavior of the class simply to modify the
        lifetime of the class (poor separation of concerns)
      – Tough to test and mock
      – Often abused and create dependencies
 • PartCreationPolicy
 • RequiredCreationPolicy
 • Factory


consulting   training   design   debugging            wintellect.com
Demo
   MVVM & Lifetime Management




consulting   training   design   debugging   wintellect.com
Bonus: Design and Test with MEF

 • Use composition for the run time
 • Use design prefixes for design-time
      – Composition will fail in the designer due to a different
        runtime for Cider, but this is fine if you follow the
        pattern described
      – Use mock utilities that can mock an object for the
         interface
 • In test, you can export a different
   implementation or simply set mocks directly

consulting   training   design   debugging              wintellect.com
Extensibility

 • Most inversion of control/dependency
   injection frameworks help wire what you
   know (bootstrapper)
 • MEF provides for what you don’t know
 • For non-extensible applications, this still
   allows for modularity
 • For extensible applications, this allows for
   plug-ins

consulting   training   design   debugging   wintellect.com
Extensibility: Dynamic XAP Files
 • First, use an AggregateCatalog to allow multiple XAP files
 • The DeploymentCatalog allows asynchronous downloads
   for XAP files
 • Use a new Silverlight Application to create satellite
   assemblies
 • CompositionHost will override the default container
 • CopyLocal = false for duplicate references
 • AllowRecomposition
 • ObservableCollection



consulting   training   design   debugging           wintellect.com
Demo
   Dynamic XAP File




consulting   training   design   debugging   wintellect.com
Metadata

 • Add additional information about an export
 • Filter exports without invoking/creating
   them
 • Allows for plug-ins to only be generated in
   context
 • Strongly typed
 • Uses the pattern Lazy<T,TMetadata>


consulting   training   design   debugging   wintellect.com
Demo
   Metadata with Jounce




consulting   training   design   debugging   wintellect.com
10 Practical Reasons to Use MEF
 1.  It’s out of the box
 2.  It provides Inversion of Control/Discovery
 3.  It gives you lifetime management
 4.  It can easily manage application wide configuration
 5.  It provides factories that resolve their own dependencies
 6.  It allows for multiple implementations of the same contract (pipeline
     and chain of responsibility)
 7. It filters with strongly-typed metadata
 8. It dynamically loads modules and extends existing applications
 9. It provides for modularity and clean separation of concerns
 10. It is completely customizable to address your specific needs (i.e.
     ExportFactory)


consulting   training   design   debugging                      wintellect.com
Questions?




                            Jeremy Likness
                            Project Manager, Senior Consultant
                            jlikness@wintellect.com



consulting   training   design   debugging                       wintellect.com

Mais conteúdo relacionado

Mais procurados

Building an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developersBuilding an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developers
kim.mens
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008
rajivmordani
 

Mais procurados (19)

10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
 
Building an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developersBuilding an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developers
 
Java Framework comparison
Java Framework comparisonJava Framework comparison
Java Framework comparison
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008
 
Dependency injection via annotations v1.0
Dependency injection via annotations v1.0Dependency injection via annotations v1.0
Dependency injection via annotations v1.0
 
01 introduction to entity framework
01   introduction to entity framework01   introduction to entity framework
01 introduction to entity framework
 
Natural Language Classifier - Handbook (IBM)
Natural Language Classifier - Handbook (IBM)Natural Language Classifier - Handbook (IBM)
Natural Language Classifier - Handbook (IBM)
 
30 Skills to Master to Become a Senior Software Engineer
30 Skills to Master to Become a Senior Software Engineer30 Skills to Master to Become a Senior Software Engineer
30 Skills to Master to Become a Senior Software Engineer
 
Drupal 8 Involvement with Promet Source
Drupal 8 Involvement with Promet SourceDrupal 8 Involvement with Promet Source
Drupal 8 Involvement with Promet Source
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design Patterns
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing Software
 
Basic Selenium Training
Basic Selenium TrainingBasic Selenium Training
Basic Selenium Training
 
Microsoft power point automation-opensourcetestingtools_matrix-1
Microsoft power point   automation-opensourcetestingtools_matrix-1Microsoft power point   automation-opensourcetestingtools_matrix-1
Microsoft power point automation-opensourcetestingtools_matrix-1
 
Get your Project back in Shape!
Get your Project back in Shape!Get your Project back in Shape!
Get your Project back in Shape!
 
jp06_bossola
jp06_bossolajp06_bossola
jp06_bossola
 
05 managing transactions
05   managing transactions05   managing transactions
05 managing transactions
 
slide to delete
slide to deleteslide to delete
slide to delete
 
software technology benchmarking
software  technology benchmarkingsoftware  technology benchmarking
software technology benchmarking
 
[English version] JavaFX and Web Integration
[English version] JavaFX and Web Integration[English version] JavaFX and Web Integration
[English version] JavaFX and Web Integration
 

Semelhante a Introduction to the Managed Extensibility Framework in Silverlight

Acing application lifecycle management in SharePoint
Acing application lifecycle management in SharePointAcing application lifecycle management in SharePoint
Acing application lifecycle management in SharePoint
Jeremy Thake
 
Intro to modern web technology
Intro to modern web technologyIntro to modern web technology
Intro to modern web technology
Chris Love
 
Wintellect - Devscovery - Enterprise JavaScript Development 2 of 2
Wintellect - Devscovery - Enterprise JavaScript Development 2 of 2Wintellect - Devscovery - Enterprise JavaScript Development 2 of 2
Wintellect - Devscovery - Enterprise JavaScript Development 2 of 2
Jeremy Likness
 
Selenium digitalinfobytes-120829005812-phpapp02
Selenium digitalinfobytes-120829005812-phpapp02Selenium digitalinfobytes-120829005812-phpapp02
Selenium digitalinfobytes-120829005812-phpapp02
Kdeepapal Mishra
 

Semelhante a Introduction to the Managed Extensibility Framework in Silverlight (20)

Building extensible application using MEF
Building extensible application using MEFBuilding extensible application using MEF
Building extensible application using MEF
 
Acing application lifecycle management in SharePoint
Acing application lifecycle management in SharePointAcing application lifecycle management in SharePoint
Acing application lifecycle management in SharePoint
 
Sitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helixSitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helix
 
Introduction to DevOps Tools | DevOps Training | DevOps Tutorial for Beginner...
Introduction to DevOps Tools | DevOps Training | DevOps Tutorial for Beginner...Introduction to DevOps Tools | DevOps Training | DevOps Tutorial for Beginner...
Introduction to DevOps Tools | DevOps Training | DevOps Tutorial for Beginner...
 
Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
 
A Day in the Life: Developer Enhancements with Visual Studio 2012
A Day in the Life: Developer Enhancements with Visual Studio 2012A Day in the Life: Developer Enhancements with Visual Studio 2012
A Day in the Life: Developer Enhancements with Visual Studio 2012
 
Full Stack DevOps - Ready To Go
Full Stack DevOps - Ready To GoFull Stack DevOps - Ready To Go
Full Stack DevOps - Ready To Go
 
Intro to modern web technology
Intro to modern web technologyIntro to modern web technology
Intro to modern web technology
 
Wintellect - Devscovery - Enterprise JavaScript Development 2 of 2
Wintellect - Devscovery - Enterprise JavaScript Development 2 of 2Wintellect - Devscovery - Enterprise JavaScript Development 2 of 2
Wintellect - Devscovery - Enterprise JavaScript Development 2 of 2
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous Integration
 
Selenium web driver_2.0_presentation
Selenium web driver_2.0_presentationSelenium web driver_2.0_presentation
Selenium web driver_2.0_presentation
 
Wintellect - Windows 8 for the Silverlight and WPF Developer
Wintellect   - Windows 8 for the Silverlight and WPF DeveloperWintellect   - Windows 8 for the Silverlight and WPF Developer
Wintellect - Windows 8 for the Silverlight and WPF Developer
 
Presentation 1 Web--dev
Presentation 1 Web--devPresentation 1 Web--dev
Presentation 1 Web--dev
 
Net Beans
Net BeansNet Beans
Net Beans
 
Net Beans
Net BeansNet Beans
Net Beans
 
Selenium digitalinfobytes-120829005812-phpapp02
Selenium digitalinfobytes-120829005812-phpapp02Selenium digitalinfobytes-120829005812-phpapp02
Selenium digitalinfobytes-120829005812-phpapp02
 
Software Engineering - chp8- deployment
Software Engineering - chp8- deploymentSoftware Engineering - chp8- deployment
Software Engineering - chp8- deployment
 
ALM with TFS: From the Drawing Board to the Cloud
ALM with TFS: From the Drawing Board to the CloudALM with TFS: From the Drawing Board to the Cloud
ALM with TFS: From the Drawing Board to the Cloud
 
Accelerate Sitecore DevOps on Microsoft Azure
Accelerate Sitecore DevOps on Microsoft AzureAccelerate Sitecore DevOps on Microsoft Azure
Accelerate Sitecore DevOps on Microsoft Azure
 
The Nuxeo Way: leveraging open source to build a world-class ECM platform
The Nuxeo Way: leveraging open source to build a world-class ECM platformThe Nuxeo Way: leveraging open source to build a world-class ECM platform
The Nuxeo Way: leveraging open source to build a world-class ECM platform
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Introduction to the Managed Extensibility Framework in Silverlight

  • 1. Intro to MEF with Silverlight Jeremy Likness Project Manager, Senior Consultant jlikness@wintellect.com Copyright © 2011 consulting training design debugging wintellect.com
  • 2. what we do consulting training design debugging who we are Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull out all the stops to help our customers achieve their goals through advanced software-based consulting and training solutions. how we do it Training • On-site instructor-led training Consulting & Debugging • Virtual instructor-led training • Architecture, analysis, and design services • Devscovery conferences • Full lifecycle custom software development • Content creation Design • Project management • User Experience Design • Debugging & performance tuning • Visual & Content Design • Video & Animation Production consulting training design debugging wintellect.com
  • 3. Agenda • Why MEF? • Discovery • Lifetime Management • Extensibility • Metadata • 10 Practical Reasons to use MEF consulting training design debugging wintellect.com
  • 4. Why MEF? • Misconception: Managed Extensibility Framework • Part of the framework • Discovery • Lifetime management • Extensibility • Metadata consulting training design debugging wintellect.com
  • 5. Welcome to the MEF Lab! • I admit I am a MEF addict! • You may be surprised by who has done MEF • Visual Studio 2010 • 2010 Vancouver Olympics • Microsoft (Looking Glass) • SharePoint consulting training design debugging wintellect.com
  • 6. Discovery • Import: Contract and Demand • Export: Implementation and Supply Look Ma! I • Part: Supply & Demand need 500 don’t constructor overloads! “I need something that implements IMessage” [Import] public IMessage MyMessenger { get; set; } [Export(typeof(IMessage))] public class SpecificMessenger : IMessage “I have something that implements IMessage” consulting training design debugging wintellect.com
  • 7. Discovery: Catalogs • Catalogs tell MEF where to find parts • AssemblyCatalog: Current assembly • TypeCatalog: List of types • DeploymentCatalog: Silverlight XAP file • AggregateCatalog: Composed of Multiple Catalogs consulting training design debugging wintellect.com
  • 8. Discovery: Container • The Container wraps the Catalog • The Container is responsible for Composition: – What parts exist? • What imports exist for a part? • What exports exist for a part? • This is the Discovery step • In Silverlight specifically the “CompositionInitializer” handles containers consulting training design debugging wintellect.com
  • 9. Discovery: Catalogs & Containers Wraps parts in the current XAP Look Ma! No var deploymentCatalog = new DeploymentCatalog(); var container = new Bootstrapper! CompositionContainer(deploymentCatalog); container.ComposeParts(this); Using the parts in the container, find all parts in the current class, then satisfy all imports with corresponding exports (“Composition”) consulting training design debugging wintellect.com
  • 10. Demo Hello, MEF! consulting training design debugging wintellect.com
  • 11. CompositionInitializer • Notice that composition happens “explicitly” with the composition call • What about XAML objects? These are created by the XAML parser, not MEF • How do you share a container across the application? • CompositionInitializer solves this problem by creating a default, global container • Must be high level: classes that use this cannot export themselves! consulting training design debugging wintellect.com
  • 12. Stable Composition • Guarantees imports are satisfied • Works throughout the entire hierarchy • Helps keep plug-ins “honest” • What about multiple plug-ins? consulting training design debugging wintellect.com
  • 13. ImportMany • Allows multiple implementations • Stable composition will reject invalid exports consulting training design debugging wintellect.com
  • 14. Demo ImportMany consulting training design debugging wintellect.com
  • 15. Lifetime Management • What’s wrong with Singletons? – Change the behavior of the class simply to modify the lifetime of the class (poor separation of concerns) – Tough to test and mock – Often abused and create dependencies • PartCreationPolicy • RequiredCreationPolicy • Factory consulting training design debugging wintellect.com
  • 16. Demo MVVM & Lifetime Management consulting training design debugging wintellect.com
  • 17. Bonus: Design and Test with MEF • Use composition for the run time • Use design prefixes for design-time – Composition will fail in the designer due to a different runtime for Cider, but this is fine if you follow the pattern described – Use mock utilities that can mock an object for the interface • In test, you can export a different implementation or simply set mocks directly consulting training design debugging wintellect.com
  • 18. Extensibility • Most inversion of control/dependency injection frameworks help wire what you know (bootstrapper) • MEF provides for what you don’t know • For non-extensible applications, this still allows for modularity • For extensible applications, this allows for plug-ins consulting training design debugging wintellect.com
  • 19. Extensibility: Dynamic XAP Files • First, use an AggregateCatalog to allow multiple XAP files • The DeploymentCatalog allows asynchronous downloads for XAP files • Use a new Silverlight Application to create satellite assemblies • CompositionHost will override the default container • CopyLocal = false for duplicate references • AllowRecomposition • ObservableCollection consulting training design debugging wintellect.com
  • 20. Demo Dynamic XAP File consulting training design debugging wintellect.com
  • 21. Metadata • Add additional information about an export • Filter exports without invoking/creating them • Allows for plug-ins to only be generated in context • Strongly typed • Uses the pattern Lazy<T,TMetadata> consulting training design debugging wintellect.com
  • 22. Demo Metadata with Jounce consulting training design debugging wintellect.com
  • 23. 10 Practical Reasons to Use MEF 1. It’s out of the box 2. It provides Inversion of Control/Discovery 3. It gives you lifetime management 4. It can easily manage application wide configuration 5. It provides factories that resolve their own dependencies 6. It allows for multiple implementations of the same contract (pipeline and chain of responsibility) 7. It filters with strongly-typed metadata 8. It dynamically loads modules and extends existing applications 9. It provides for modularity and clean separation of concerns 10. It is completely customizable to address your specific needs (i.e. ExportFactory) consulting training design debugging wintellect.com
  • 24. Questions? Jeremy Likness Project Manager, Senior Consultant jlikness@wintellect.com consulting training design debugging wintellect.com

Notas do Editor

  1. I’ve been talking about MEF for awhile. At many of my talks, I’m stopped with “Jeremy, hold on, you’re showing us advanced uses of MEF. But why do I even want to use MEF in the first? What is it exactly that MEF does?”
  2. Discovery is what most people are looking to do when they implement Inversion of Control and Dependency Injection. There are many ways to do discovery from factories and service locators to bootstrappers and IoC containers. MEF provides a very simple and straightforward way to handle discovery.
  3. Copy the Hello MEF. Convert to a ListBox. Change Text to an array and then set the items source.
  4. Creation policies are run always once, when the imports are satisfied. Factory is unique in that it provides a means for creating new instances, and works independent of the part creation policy.
  5. This demo is a full-fledged MEF/MVVM solution. It shows not only the lifetime management concept, but how MEF works with MVVM to drive Silverlight applications. It also shows design-time support with MEF.
  6. Copy the import many. Add an aggregate catalog and use that in the container and introduce CompositionHost. Disable the button on click. Change the text to an observable collection, then add the new project with the export. Show that the button click does NOT actually pull the new export. Then add AllowRecomposition and show it working.
  7. Jounce is a framework that provides specific guidance for MVVM with MEF.
  8. If time permits, go back to some of the case studies and discuss how they worked with MEF.