SlideShare a Scribd company logo
1 of 47
Managed Extensibility Framework Deep Dive Piotr Włodek
Agenda Managed Extensibility Framework Extending MEF
Breaks up large chunks of functionality into smaller pieces Allows the teams to work in parallel Allows to deliver additional functionality by 3rd parties Isolation – if a plugin crashes, the rest of the app keeps working Plug-ins Modules Managed Addin Framework
Design pattern Creates graphs of objects Manages dependencies between objects Manages lifetime of the objects Dependency Injection P&P Unity 2.0 public SampleViewModel(     IShell shell,     ISampleView view,     IEventAggregator eventAggregator,     IPersistenceFacade persistenceManager,     ILoggerService loggerService,     IExceptionManager exceptionManager,     IWindowManagerExt windowManager) { ... } Autofac Ninject Castle
IoC + MAF = MEF ? Managed Addin Framework IoC Container Managed Extensibility Framework
An extensible framework for composing applications from a set of loosely-coupled componentsdiscovered and evolving at runtime  Applications are no longer statically compiled, they are dynamically composed(Recomposition) Supported in BCL 4.0 and Silverlight 4  Available for .NET 3.5 / SL 3 (Codeplex Drop 9) MEF 2 Drop 2 available for download! Lives in the System.ComponentModel.Composition.dll SL has also some additional stuff in the System.ComponentModel.Composition.Initialization.dll Managed Extensibility Framework
Composable parts. Application consists of composable parts
Parts. Exports. Imports. import import import Part export export
PartDefinition is a blueprint for a Part(similar to .NET Type and Object) Part represents the exported value Parts and their definitions. Object GetExportedValue() import import import Part export export import import CreatePart() PartDefinition PartDefinition export export
Exportit. [Export(typeof(ILogger))] public class Logger : ILogger {     public void Info(string message)     {         Console.WriteLine(message);     } } Logger ILogger Export
Importit. public class Program { [Import] public ILogger Logger { get; set; } private static void Main() {     var p = new Program();     p.Run(); } } Program ILogger Import
Container takes parts from catalogs. PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition Catalog Catalog Catalog Catalog CompositionContainer
Composeit. import import import import import import import part part part part import import export export export export Composition Container part part part part part part
Composeit. Catalogsprovide composableparts. Compose Catalog
Composeit. Container wires up composable parts together. Compose Catalog
Compose it. private void Run() {     var catalog = new AssemblyCatalog(...);     var container =          new CompositionContainer(catalog);     container.ComposeParts(this);     Logger.Info("Hello World!"); } Program Compose
Demo 1 – MEF basics
AvailableCatalogs. AggregateCatalog DirectoryCatalog DeploymentCatalog AssemblyCatalog TypeCatalog
Types Properties Fields Methods Exportable components.
Exportit. public class Utils { [Export("Logger.Prompt")]     public string LoggerPrompt {         get { return "Logger Prompt: "; }     } [Export("Logger.ProcessText")]     public string Process(string input) {        ...     } } Utils "Logger.Prompt„ "Logger.ProcessText" Export
Importit. [Export(typeof(ILogger))] public class FunnyLogger : ILogger {     [Import("Logger.Prompt")]     private string m_Prompt; [Import("Logger.ProcessText")]     private Func<string, string> m_TextFun; } Funny Logger "Logger.Prompt" "Logger.ProcessText" Import
DEMO 2 – EXPORTS
Which parts goes together ? import import import part export export ? import part
Demo 3 - WidgetS
Metadata. Where to place that widget ? Widget Widget
Exportit. Metadata. [Export(typeof(IWidget))] [ExportMetadata("Location", WidgetLocation.Right)] public partial class TwitterWidget : ITwitterWidget { [Import]     public TwitterWidgetPresentationModel PresentationModel     {         get;         set;     } } Twitter Widget Put me on the right Export IWidget
Importit. Metadata. [Export] public class ShellPresentationModel { [ImportMany]     public Lazy<IWidget, IWidgetMetadata>[] Widgets      { get; private set; } } ShellPM Collection of Lazy IWidgets with IWidgetMetadata  Import
Demo 4 – Widgets and metadata
Exportit. In a customway. [Export(typeof(IWidget))] [ExportMetadata("Location", WidgetLocation.Right)] public partial class TwitterWidget : ITwitterWidget { [Import]     public TwitterWidgetPresentationModel Model     {         get;         set;     } } Twitter Widget Put me on the right IWidget Export
Exportit. In a customway. [Widget(WidgetLocation.Right)] public partial class TwitterWidget : ITwitterWidget { [Import]     public TwitterWidgetPresentationModel Model     {         get;         set;     } } Twitter Widget Put me on the right IWidget Export
Demo 5 – custom export
Recomposition. Parts introduced to or removed from the container may have an impact on this import – a part can opt-in to allow this recomposition. part Compose() part part? part CompositionContainer Catalog Catalog Catalog PartDefinition PartDefinition PartDefinition PartDefinition
Recomposition. [Export] public class ShellPresentationModel { [ImportMany(AllowRecomposition = true)]     public Lazy<IWidget, IWidgetMetadata>[] Widgets    {         get; private set;    } } ShellPM Collection of Lazy IWidgets with IWidgetMetadata  Import
DEMO 5 - recomposition
Stable composition. Parts with missing required imports are rejected. part requires zero or more requires part part requires part part requires missing
Demo 6 – Stable composition
Visual Studio Output Window Microsoft.ComponentModel.Composition.Diagnostics.dll Mefx mefx /file:MyAddIn.dll /directory:dir /rejected /verbose Debugging MEF [Part] ClassLibrary1.ChainOne from: AssemblyCatalog (Assembly="ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") [Primary Rejection]  [Export] ClassLibrary1.ChainOne (ContractName="ClassLibrary1.ChainOne")  [Exception] System.ComponentModel.Composition.ImportCardinalityMismatchException: No valid exports were found that match the constraint '((exportDefinition.ContractName == "ClassLibrary1.ChainTwo") AndAlso exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "ClassLibrary1.ChainTwo".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected.
Visual MEFX
Demo 7 – debugging mef
Trim up your apps, break up your xaps! Available only in Silverlight DeploymentCatalog
Demo 8 – deployment catalog
A set of extensions developed by community Where can I find it ? www.mefcontrib.com www.mefcontrib.codeplex.com http://github.com/MefContrib/ MefContrib MefContrib-Samples MefContrib-Tools MEF Contrib
InterceptingCatalog– enables interception ConventionCatalog– conventions based programming model FilteringCatalog – enables parts filtering based on any criteria GenericCatalog – enables support for open-generics FactoryExportProvider – factory based registration IoC integration layer – MEF / Unity MefContrib – what’s in it for me?
Demo 9 – mef contrib
Extending MEF MEF Programming Models Export Providers
Export Providers. CompositionContainer CatalogExportProvider ExportProvider ExportProvider Catalog AggregateExportProvider CatalogExportProvider ExportProvider ExportProvider CompositionContainer ExportProvider
MEF ships with Attributed programming model Programming models are extensible Programming models. MEF Primitives ReflectionModelServices ExportDef PartDef ImportDef

More Related Content

What's hot

Building Eclipse Plugins
Building Eclipse PluginsBuilding Eclipse Plugins
Building Eclipse PluginsLiran Zelkha
 
3/3 : The path to CDI 2.0 - Antoine Sabot-Durand
3/3 : The path to CDI 2.0 - Antoine Sabot-Durand3/3 : The path to CDI 2.0 - Antoine Sabot-Durand
3/3 : The path to CDI 2.0 - Antoine Sabot-DurandSOAT
 
Oracle Forms: Introduction to multiple Forms
Oracle Forms: Introduction to multiple FormsOracle Forms: Introduction to multiple Forms
Oracle Forms: Introduction to multiple FormsSekhar Byna
 
ITU - MDD - Eclipse Plug-ins
ITU - MDD - Eclipse Plug-insITU - MDD - Eclipse Plug-ins
ITU - MDD - Eclipse Plug-insTonny Madsen
 
Lap around .net 4
Lap around .net 4Lap around .net 4
Lap around .net 4Abdul Khan
 
Announcing asp.net core updates in .net 5 preview 8
Announcing asp.net core updates in .net 5 preview 8Announcing asp.net core updates in .net 5 preview 8
Announcing asp.net core updates in .net 5 preview 8Concetto Labs
 
1/3 : introduction to CDI - Antoine Sabot-Durand
1/3 : introduction to CDI - Antoine Sabot-Durand1/3 : introduction to CDI - Antoine Sabot-Durand
1/3 : introduction to CDI - Antoine Sabot-DurandSOAT
 
2/3 : CDI advanced - Antoine Sabot-Durand
2/3 : CDI advanced - Antoine Sabot-Durand2/3 : CDI advanced - Antoine Sabot-Durand
2/3 : CDI advanced - Antoine Sabot-DurandSOAT
 
Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?BugRaptors
 
Reusable Build Scripts for Managed Package Development (October 14, 2014)
Reusable Build Scripts for Managed Package Development (October 14, 2014)Reusable Build Scripts for Managed Package Development (October 14, 2014)
Reusable Build Scripts for Managed Package Development (October 14, 2014)Salesforce Partners
 
Introduction to Continuous Integration
Introduction to Continuous IntegrationIntroduction to Continuous Integration
Introduction to Continuous IntegrationHùng Nguyễn Huy
 
Marathon Testing Tool
Marathon Testing ToolMarathon Testing Tool
Marathon Testing Toolnarayan dudhe
 
CodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.comCodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.comChristopher Cubos
 
JUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMJUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMSam Brannen
 
Selenium Test Automation
Selenium Test AutomationSelenium Test Automation
Selenium Test AutomationBabuDevanandam
 
How to commit a project in svn using svn plugin in anypoint studio
How to commit a project in svn using svn plugin in anypoint studioHow to commit a project in svn using svn plugin in anypoint studio
How to commit a project in svn using svn plugin in anypoint studioSudha Ch
 
Softwaretestingtoolsfreeandopensourcefinal 150411221750-conversion-gate01
Softwaretestingtoolsfreeandopensourcefinal 150411221750-conversion-gate01Softwaretestingtoolsfreeandopensourcefinal 150411221750-conversion-gate01
Softwaretestingtoolsfreeandopensourcefinal 150411221750-conversion-gate01Aravindharamanan S
 
JUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVMJUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVMVMware Tanzu
 
Deployment automation framework with selenium
Deployment automation framework with seleniumDeployment automation framework with selenium
Deployment automation framework with seleniumWenhua Wang
 

What's hot (20)

Building Eclipse Plugins
Building Eclipse PluginsBuilding Eclipse Plugins
Building Eclipse Plugins
 
3/3 : The path to CDI 2.0 - Antoine Sabot-Durand
3/3 : The path to CDI 2.0 - Antoine Sabot-Durand3/3 : The path to CDI 2.0 - Antoine Sabot-Durand
3/3 : The path to CDI 2.0 - Antoine Sabot-Durand
 
Oracle Forms: Introduction to multiple Forms
Oracle Forms: Introduction to multiple FormsOracle Forms: Introduction to multiple Forms
Oracle Forms: Introduction to multiple Forms
 
ITU - MDD - Eclipse Plug-ins
ITU - MDD - Eclipse Plug-insITU - MDD - Eclipse Plug-ins
ITU - MDD - Eclipse Plug-ins
 
Lap around .net 4
Lap around .net 4Lap around .net 4
Lap around .net 4
 
Announcing asp.net core updates in .net 5 preview 8
Announcing asp.net core updates in .net 5 preview 8Announcing asp.net core updates in .net 5 preview 8
Announcing asp.net core updates in .net 5 preview 8
 
1/3 : introduction to CDI - Antoine Sabot-Durand
1/3 : introduction to CDI - Antoine Sabot-Durand1/3 : introduction to CDI - Antoine Sabot-Durand
1/3 : introduction to CDI - Antoine Sabot-Durand
 
2/3 : CDI advanced - Antoine Sabot-Durand
2/3 : CDI advanced - Antoine Sabot-Durand2/3 : CDI advanced - Antoine Sabot-Durand
2/3 : CDI advanced - Antoine Sabot-Durand
 
Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?
 
Reusable Build Scripts for Managed Package Development (October 14, 2014)
Reusable Build Scripts for Managed Package Development (October 14, 2014)Reusable Build Scripts for Managed Package Development (October 14, 2014)
Reusable Build Scripts for Managed Package Development (October 14, 2014)
 
Introduction to Continuous Integration
Introduction to Continuous IntegrationIntroduction to Continuous Integration
Introduction to Continuous Integration
 
Marathon Testing Tool
Marathon Testing ToolMarathon Testing Tool
Marathon Testing Tool
 
Selenium
SeleniumSelenium
Selenium
 
CodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.comCodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.com
 
JUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMJUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVM
 
Selenium Test Automation
Selenium Test AutomationSelenium Test Automation
Selenium Test Automation
 
How to commit a project in svn using svn plugin in anypoint studio
How to commit a project in svn using svn plugin in anypoint studioHow to commit a project in svn using svn plugin in anypoint studio
How to commit a project in svn using svn plugin in anypoint studio
 
Softwaretestingtoolsfreeandopensourcefinal 150411221750-conversion-gate01
Softwaretestingtoolsfreeandopensourcefinal 150411221750-conversion-gate01Softwaretestingtoolsfreeandopensourcefinal 150411221750-conversion-gate01
Softwaretestingtoolsfreeandopensourcefinal 150411221750-conversion-gate01
 
JUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVMJUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVM
 
Deployment automation framework with selenium
Deployment automation framework with seleniumDeployment automation framework with selenium
Deployment automation framework with selenium
 

Similar to MEF Deep Dive by Piotr Wlodek

Extending the Enterprise with MEF
Extending the Enterprise with MEFExtending the Enterprise with MEF
Extending the Enterprise with MEFBrian Ritchie
 
Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)Mohamed Meligy
 
Managed extensibility framework
Managed extensibility frameworkManaged extensibility framework
Managed extensibility frameworkLarry Nung
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to GriffonJames Williams
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaRainer Stropek
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEBenjamin Cabé
 
Steps how to create active x using visual studio 2008
Steps how to create active x using visual studio 2008Steps how to create active x using visual studio 2008
Steps how to create active x using visual studio 2008Yudep Apoi
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6William Marques
 
Developer Student Clubs NUK - Flutter for Beginners
Developer Student Clubs NUK - Flutter for BeginnersDeveloper Student Clubs NUK - Flutter for Beginners
Developer Student Clubs NUK - Flutter for BeginnersJiaxuan Lin
 
Navigating the wild seas of es6 modules
Navigating the wild seas of es6 modulesNavigating the wild seas of es6 modules
Navigating the wild seas of es6 modulesGil Tayar
 
BOF-5110 Extending the Groovy SwingBuilder
BOF-5110 Extending the Groovy SwingBuilderBOF-5110 Extending the Groovy SwingBuilder
BOF-5110 Extending the Groovy SwingBuilderDanno Ferrin
 
How to build to do app using vue composition api and vuex 4 with typescript
How to build to do app using vue composition api and vuex 4 with typescriptHow to build to do app using vue composition api and vuex 4 with typescript
How to build to do app using vue composition api and vuex 4 with typescriptKaty Slemon
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotTsai Tsung-Yi
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorialAnh Quân
 

Similar to MEF Deep Dive by Piotr Wlodek (20)

Extending the Enterprise with MEF
Extending the Enterprise with MEFExtending the Enterprise with MEF
Extending the Enterprise with MEF
 
Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)
 
Meteor
MeteorMeteor
Meteor
 
Swing
SwingSwing
Swing
 
MEF
MEFMEF
MEF
 
Managed extensibility framework
Managed extensibility frameworkManaged extensibility framework
Managed extensibility framework
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA Austria
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDE
 
Steps how to create active x using visual studio 2008
Steps how to create active x using visual studio 2008Steps how to create active x using visual studio 2008
Steps how to create active x using visual studio 2008
 
Griffon Presentation
Griffon PresentationGriffon Presentation
Griffon Presentation
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
Gephi Toolkit Tutorial
Gephi Toolkit TutorialGephi Toolkit Tutorial
Gephi Toolkit Tutorial
 
Developer Student Clubs NUK - Flutter for Beginners
Developer Student Clubs NUK - Flutter for BeginnersDeveloper Student Clubs NUK - Flutter for Beginners
Developer Student Clubs NUK - Flutter for Beginners
 
Navigating the wild seas of es6 modules
Navigating the wild seas of es6 modulesNavigating the wild seas of es6 modules
Navigating the wild seas of es6 modules
 
BOF-5110 Extending the Groovy SwingBuilder
BOF-5110 Extending the Groovy SwingBuilderBOF-5110 Extending the Groovy SwingBuilder
BOF-5110 Extending the Groovy SwingBuilder
 
How to build to do app using vue composition api and vuex 4 with typescript
How to build to do app using vue composition api and vuex 4 with typescriptHow to build to do app using vue composition api and vuex 4 with typescript
How to build to do app using vue composition api and vuex 4 with typescript
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobot
 
Google GIN
Google GINGoogle GIN
Google GIN
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
 

More from infusiondev

Learning by the Lake
Learning by the LakeLearning by the Lake
Learning by the Lakeinfusiondev
 
Toronto Blue Jays Game
Toronto Blue Jays GameToronto Blue Jays Game
Toronto Blue Jays Gameinfusiondev
 
HOPE Volleyball 2011
HOPE Volleyball 2011HOPE Volleyball 2011
HOPE Volleyball 2011infusiondev
 
Infusion Lunch n Learns
Infusion Lunch n LearnsInfusion Lunch n Learns
Infusion Lunch n Learnsinfusiondev
 
Sleepless london 2011
Sleepless london 2011Sleepless london 2011
Sleepless london 2011infusiondev
 
Sleepless London 2011
Sleepless London 2011Sleepless London 2011
Sleepless London 2011infusiondev
 
Infusion Dubai Bootcamp
Infusion Dubai BootcampInfusion Dubai Bootcamp
Infusion Dubai Bootcampinfusiondev
 
Infusion London Casino Night
Infusion London Casino NightInfusion London Casino Night
Infusion London Casino Nightinfusiondev
 
New Toronto Office
New Toronto OfficeNew Toronto Office
New Toronto Officeinfusiondev
 
Infusion New York Casino Night
Infusion New York Casino NightInfusion New York Casino Night
Infusion New York Casino Nightinfusiondev
 
Paintball at Infusion Toronto
Paintball at Infusion TorontoPaintball at Infusion Toronto
Paintball at Infusion Torontoinfusiondev
 
Easter Egg Drop Off
Easter Egg Drop OffEaster Egg Drop Off
Easter Egg Drop Offinfusiondev
 
Infusion Olympics
Infusion OlympicsInfusion Olympics
Infusion Olympicsinfusiondev
 
Infusion Charity Poker Tournament
Infusion Charity Poker TournamentInfusion Charity Poker Tournament
Infusion Charity Poker Tournamentinfusiondev
 
Did You Know - Infusion's Accomplishments in 2010
Did You Know - Infusion's Accomplishments in 2010Did You Know - Infusion's Accomplishments in 2010
Did You Know - Infusion's Accomplishments in 2010infusiondev
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancementsinfusiondev
 
Top 10 reasons to Join Infusion
Top 10 reasons to Join InfusionTop 10 reasons to Join Infusion
Top 10 reasons to Join Infusioninfusiondev
 
Bing Maps Snapshot
Bing Maps SnapshotBing Maps Snapshot
Bing Maps Snapshotinfusiondev
 

More from infusiondev (20)

Learning by the Lake
Learning by the LakeLearning by the Lake
Learning by the Lake
 
Toronto Blue Jays Game
Toronto Blue Jays GameToronto Blue Jays Game
Toronto Blue Jays Game
 
HOPE Volleyball 2011
HOPE Volleyball 2011HOPE Volleyball 2011
HOPE Volleyball 2011
 
Infusion Lunch n Learns
Infusion Lunch n LearnsInfusion Lunch n Learns
Infusion Lunch n Learns
 
Sleepless london 2011
Sleepless london 2011Sleepless london 2011
Sleepless london 2011
 
Sleepless London 2011
Sleepless London 2011Sleepless London 2011
Sleepless London 2011
 
Infusion Dubai Bootcamp
Infusion Dubai BootcampInfusion Dubai Bootcamp
Infusion Dubai Bootcamp
 
Infusion London Casino Night
Infusion London Casino NightInfusion London Casino Night
Infusion London Casino Night
 
New Toronto Office
New Toronto OfficeNew Toronto Office
New Toronto Office
 
Infusion New York Casino Night
Infusion New York Casino NightInfusion New York Casino Night
Infusion New York Casino Night
 
Paintball at Infusion Toronto
Paintball at Infusion TorontoPaintball at Infusion Toronto
Paintball at Infusion Toronto
 
Easter Egg Drop Off
Easter Egg Drop OffEaster Egg Drop Off
Easter Egg Drop Off
 
Infusion Olympics
Infusion OlympicsInfusion Olympics
Infusion Olympics
 
Infusion Charity Poker Tournament
Infusion Charity Poker TournamentInfusion Charity Poker Tournament
Infusion Charity Poker Tournament
 
Red Nose Day
Red Nose DayRed Nose Day
Red Nose Day
 
Did You Know - Infusion's Accomplishments in 2010
Did You Know - Infusion's Accomplishments in 2010Did You Know - Infusion's Accomplishments in 2010
Did You Know - Infusion's Accomplishments in 2010
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancements
 
Top 10 reasons to Join Infusion
Top 10 reasons to Join InfusionTop 10 reasons to Join Infusion
Top 10 reasons to Join Infusion
 
PDAC 2011
PDAC 2011PDAC 2011
PDAC 2011
 
Bing Maps Snapshot
Bing Maps SnapshotBing Maps Snapshot
Bing Maps Snapshot
 

Recently uploaded

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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 FresherRemote DBA Services
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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 DiscoveryTrustArc
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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 WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Recently uploaded (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

MEF Deep Dive by Piotr Wlodek

  • 1. Managed Extensibility Framework Deep Dive Piotr Włodek
  • 2. Agenda Managed Extensibility Framework Extending MEF
  • 3. Breaks up large chunks of functionality into smaller pieces Allows the teams to work in parallel Allows to deliver additional functionality by 3rd parties Isolation – if a plugin crashes, the rest of the app keeps working Plug-ins Modules Managed Addin Framework
  • 4. Design pattern Creates graphs of objects Manages dependencies between objects Manages lifetime of the objects Dependency Injection P&P Unity 2.0 public SampleViewModel( IShell shell, ISampleView view, IEventAggregator eventAggregator, IPersistenceFacade persistenceManager, ILoggerService loggerService, IExceptionManager exceptionManager, IWindowManagerExt windowManager) { ... } Autofac Ninject Castle
  • 5. IoC + MAF = MEF ? Managed Addin Framework IoC Container Managed Extensibility Framework
  • 6. An extensible framework for composing applications from a set of loosely-coupled componentsdiscovered and evolving at runtime Applications are no longer statically compiled, they are dynamically composed(Recomposition) Supported in BCL 4.0 and Silverlight 4 Available for .NET 3.5 / SL 3 (Codeplex Drop 9) MEF 2 Drop 2 available for download! Lives in the System.ComponentModel.Composition.dll SL has also some additional stuff in the System.ComponentModel.Composition.Initialization.dll Managed Extensibility Framework
  • 7. Composable parts. Application consists of composable parts
  • 8. Parts. Exports. Imports. import import import Part export export
  • 9. PartDefinition is a blueprint for a Part(similar to .NET Type and Object) Part represents the exported value Parts and their definitions. Object GetExportedValue() import import import Part export export import import CreatePart() PartDefinition PartDefinition export export
  • 10. Exportit. [Export(typeof(ILogger))] public class Logger : ILogger { public void Info(string message) { Console.WriteLine(message); } } Logger ILogger Export
  • 11. Importit. public class Program { [Import] public ILogger Logger { get; set; } private static void Main() { var p = new Program(); p.Run(); } } Program ILogger Import
  • 12. Container takes parts from catalogs. PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition PartDefinition Catalog Catalog Catalog Catalog CompositionContainer
  • 13. Composeit. import import import import import import import part part part part import import export export export export Composition Container part part part part part part
  • 15. Composeit. Container wires up composable parts together. Compose Catalog
  • 16. Compose it. private void Run() { var catalog = new AssemblyCatalog(...); var container = new CompositionContainer(catalog); container.ComposeParts(this); Logger.Info("Hello World!"); } Program Compose
  • 17. Demo 1 – MEF basics
  • 18. AvailableCatalogs. AggregateCatalog DirectoryCatalog DeploymentCatalog AssemblyCatalog TypeCatalog
  • 19. Types Properties Fields Methods Exportable components.
  • 20. Exportit. public class Utils { [Export("Logger.Prompt")] public string LoggerPrompt { get { return "Logger Prompt: "; } } [Export("Logger.ProcessText")] public string Process(string input) { ... } } Utils "Logger.Prompt„ "Logger.ProcessText" Export
  • 21. Importit. [Export(typeof(ILogger))] public class FunnyLogger : ILogger { [Import("Logger.Prompt")] private string m_Prompt; [Import("Logger.ProcessText")] private Func<string, string> m_TextFun; } Funny Logger "Logger.Prompt" "Logger.ProcessText" Import
  • 22. DEMO 2 – EXPORTS
  • 23. Which parts goes together ? import import import part export export ? import part
  • 24. Demo 3 - WidgetS
  • 25. Metadata. Where to place that widget ? Widget Widget
  • 26. Exportit. Metadata. [Export(typeof(IWidget))] [ExportMetadata("Location", WidgetLocation.Right)] public partial class TwitterWidget : ITwitterWidget { [Import] public TwitterWidgetPresentationModel PresentationModel { get; set; } } Twitter Widget Put me on the right Export IWidget
  • 27. Importit. Metadata. [Export] public class ShellPresentationModel { [ImportMany] public Lazy<IWidget, IWidgetMetadata>[] Widgets { get; private set; } } ShellPM Collection of Lazy IWidgets with IWidgetMetadata Import
  • 28. Demo 4 – Widgets and metadata
  • 29. Exportit. In a customway. [Export(typeof(IWidget))] [ExportMetadata("Location", WidgetLocation.Right)] public partial class TwitterWidget : ITwitterWidget { [Import] public TwitterWidgetPresentationModel Model { get; set; } } Twitter Widget Put me on the right IWidget Export
  • 30. Exportit. In a customway. [Widget(WidgetLocation.Right)] public partial class TwitterWidget : ITwitterWidget { [Import] public TwitterWidgetPresentationModel Model { get; set; } } Twitter Widget Put me on the right IWidget Export
  • 31. Demo 5 – custom export
  • 32. Recomposition. Parts introduced to or removed from the container may have an impact on this import – a part can opt-in to allow this recomposition. part Compose() part part? part CompositionContainer Catalog Catalog Catalog PartDefinition PartDefinition PartDefinition PartDefinition
  • 33. Recomposition. [Export] public class ShellPresentationModel { [ImportMany(AllowRecomposition = true)] public Lazy<IWidget, IWidgetMetadata>[] Widgets { get; private set; } } ShellPM Collection of Lazy IWidgets with IWidgetMetadata Import
  • 34. DEMO 5 - recomposition
  • 35. Stable composition. Parts with missing required imports are rejected. part requires zero or more requires part part requires part part requires missing
  • 36. Demo 6 – Stable composition
  • 37. Visual Studio Output Window Microsoft.ComponentModel.Composition.Diagnostics.dll Mefx mefx /file:MyAddIn.dll /directory:dir /rejected /verbose Debugging MEF [Part] ClassLibrary1.ChainOne from: AssemblyCatalog (Assembly="ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") [Primary Rejection] [Export] ClassLibrary1.ChainOne (ContractName="ClassLibrary1.ChainOne") [Exception] System.ComponentModel.Composition.ImportCardinalityMismatchException: No valid exports were found that match the constraint '((exportDefinition.ContractName == "ClassLibrary1.ChainTwo") AndAlso exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "ClassLibrary1.ChainTwo".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected.
  • 39. Demo 7 – debugging mef
  • 40. Trim up your apps, break up your xaps! Available only in Silverlight DeploymentCatalog
  • 41. Demo 8 – deployment catalog
  • 42. A set of extensions developed by community Where can I find it ? www.mefcontrib.com www.mefcontrib.codeplex.com http://github.com/MefContrib/ MefContrib MefContrib-Samples MefContrib-Tools MEF Contrib
  • 43. InterceptingCatalog– enables interception ConventionCatalog– conventions based programming model FilteringCatalog – enables parts filtering based on any criteria GenericCatalog – enables support for open-generics FactoryExportProvider – factory based registration IoC integration layer – MEF / Unity MefContrib – what’s in it for me?
  • 44. Demo 9 – mef contrib
  • 45. Extending MEF MEF Programming Models Export Providers
  • 46. Export Providers. CompositionContainer CatalogExportProvider ExportProvider ExportProvider Catalog AggregateExportProvider CatalogExportProvider ExportProvider ExportProvider CompositionContainer ExportProvider
  • 47. MEF ships with Attributed programming model Programming models are extensible Programming models. MEF Primitives ReflectionModelServices ExportDef PartDef ImportDef
  • 48. + Ease of programming + Resolves dependencies between components + Automatic component discovery + Can compose types, fields, props and methods - Slower than the IoC containers - Lack of some IoC features Method injection Assisted injection Lifetime management - No component separation (separate appdomain, process) MEF vs IoC vs MAF
  • 49. Managed Extensibility Framework http://mef.codeplex.com/ MEF in MSDN Magazine http://msdn.microsoft.com/en-us/magazine/ee291628.aspx MEF Contrib http://mefcontrib.com/ Glenn Block’s Blog http://blogs.msdn.com/b/gblock/ Piotr Włodek’s Blog http://pwlodek.blogspot.com/ Useful links

Editor's Notes

  1. We are gonna talks about MEF, and how to write EXTENSIBLE applications!
  2. DI is a design pattern in witch a special entity, usualy a container, is responsible for creating and managing the graph object.If you were to create the instance yourself you would have to inject all dependencies yourself.
  3. MEF combines the best features of the IoC frameworks with MAF
  4. Composable part is MEF’s representation of a class instance.
  5. MEF out of the box ships with the Attributed Programming Model.
  6. MEF composes available parts together.
  7. MEF doesn’t allow to create parts in inconsistent state.