SlideShare una empresa de Scribd logo
1 de 24
Extending the Enterprise
with MEF
Building extensibility into your enterprise apps with
the Managed Extensibility Framework



Brian Ritchie                          Jason Gerard
Chief Architect                        Director of Product Development
PaySpan, Inc.                          PaySpan, Inc.

Twitter: @brian_ritchie                Twitter: @thejasongerard
Email: brian.ritchie@gmail.com         Email: jason.gerard@gmail.com
Blog: http://weblog.asp.net/britchie   Blog: http://jasongerard.wordpress.com
Web: http://www.dotnetpowered.com
Who are we?

Brian Ritchie               Jason Gerard
» Chief Architect           » Director of Development
» Nearly 20 years of        » Nearly 15 years of
  development experience      development experience
» Developing on .NET        » Only fault is that he is only
  since 1.0 Beta 1.           one man
  Contributor to Mono and
  other open source
  projects
Managed Extensibility Framework

Agenda
»What is MEF?
»When to use MEF
»Benefits of using MEF
»Key Concepts
»What’s new in .NET 4.5?
»Demo!
What is MEF?
The Managed Extensibility Framework or MEF
is a library for creating lightweight, extensible
applications.
»It allows application developers to discover and use
extensions with no configuration required. It lets
extension developers easily encapsulate code and
avoid fragile hard dependencies. MEF not only allows
extensions to be reused within applications, but across
applications as well.
When to use MEF?




And when not to...
When to use MEF?
» You are planning to star in a zombie movie
» You weren’t born in Britain but want British
  teeth.
                          NO!


            We’re talking about MEF not METH!!
When to use MEF?
» Only if you are building an extensible UI
  with Silverlight or WPF applications

                                     NO!


Building extensible applications is one of the key nonfunctional requirements in
enterprise application development scenarios.
                                                          .NET 4 for Enterprise
                                                      Architects and Developers
When to use MEF?
» When you need a general purpose
  Dependency Injection framework or an
  Inversion of Control Container
                                 NO!

 We are not aiming for MEF to be an all-purpose IoC. The best way to
 think about the IoC aspects of MEF is an implementation detail. We
 use IoC as a pattern because it is a great way to address the problems
 we are looking to solve.
                                                             Glenn Block
                                                                Microsoft
When to use MEF?
» MEF is especially useful for large applications
  where injecting the dependencies between distant
  parts would get hard to manage as the size of the
  code base increases.
                         YES!
  MEF is focused on extensibility. When you think of MEF look at it as an
  investment in taking our platform forward. Our future products and the
  platform will leverage MEF as a standard mechanism for adding
  extensibility.
  Imagine when you want to extend our platform in the future, you drop a
  DLL in the bin folder and you are done. The MEF enabled app lights up
  with the new extension. That's the vision for MEF.
                                                                Glenn Block
                                                                   Microsoft
Benefits of being a MEF user

» Decomposes large systems into building
  blocks
» Allows extensibility across teams
» Turns your app into a platform
MEF Key Concepts




Ready to get hooked
           on MEF?
MEF Key Concepts
Exports & Imports
»Exports expose contracts for functionality
that can be replaced at runtime. Exports are
defined in your plugin libraries.
»Imports are properties that consume
Exported instances. Imports are defined in
your host application.
MEF Key Concepts
» Exports
  Decorating a class with the Export attribute

       [Export(typeof(IPlugin)]
        [Export(typeof(IPlugin)]
       public class MyPlugin :: IPlugin
        public class MyPlugin    IPlugin
       {{


       }}




 The interface (IPlugin) should be in Contract Assembly that can be
   shared between the importer (host application) and the exporter
                                (plugin).
MEF Key Concepts
» Imports
  Decorating the host class with an
  ImportMany attribute

         public class Host
          public class Host
         {{
            [ImportMany(typeof(IPlugin))]
             [ImportMany(typeof(IPlugin))]
            public IEnumberable<IPlugin> Plugins {{ get; set; }}
             public IEnumberable<IPlugin> Plugins    get; set;

              ...
               ...
         }}




The interface (IPlugin) should be in Contract Assembly that can be
 shared between the importer (host application) and the exporter
                             (plugin).
MEF Key Concepts
» Imports
  Exports can also define imports. For
  example, a plugin maybe dependent on a
  service from the host.

      [Export(typeof(IPlugin)]
       [Export(typeof(IPlugin)]
      public class MyPlugin :: IPlugin
       public class MyPlugin    IPlugin
      {{
      [Import]
       [Import]
      IService Dependency {{ get; set; }}
       IService Dependency    get; set;

      }}
MEF Key Concepts
Composition
»Composition binds the Export with an Import
at runtime to deliver the functionality.
»A Catalog hosts the exports that need to be
composed.
»Types of catalogs:
  »   Assembly Catalog
  »   Directory Catalog
  »   Aggregate Catalog
  »   Type Catalog
MEF Key Concepts
Composition
»Loading a catalog and binding the exports to
the imports:

      var catalog == new DirectoryCatalog(@".plugins");
       var catalog    new DirectoryCatalog(@".plugins");

      var container == new CompositionContainer(catalog);
       var container    new CompositionContainer(catalog);

      container.ComposeParts(host);
       container.ComposeParts(host);
MEF Key Concepts
Composition
»The Plugins collection now contains
instances of all the exported types.

      public class Host
       public class Host
      {{
         [ImportMany(typeof(IPlugin))]
          [ImportMany(typeof(IPlugin))]
         public IEnumberable<IPlugin> Plugins {{ get; set; }}
          public IEnumberable<IPlugin> Plugins    get; set;

           ...
            ...
      }}
MEF Key Concepts
Metadata
»Custom metadata can be attached to your
exported types to provide information to the
importer.
»Simply add an ExportMetadata attribute
which accepts a key and a value:
      [ExportMetadata(“ID”, 1)]
       [ExportMetadata(“ID”, 1)]
      [Export(typeof(IPlugin)]
       [Export(typeof(IPlugin)]
      public class MyPlugin :: IPlugin
       public class MyPlugin    IPlugin
      {{



      }}
MEF Key Concepts
Metadata
»In the importer, define an Interface to access
the metadata. The property and data type
must match the name/value pair specified in
the ExportMetadata attribute.

    public interface PluginMetadata
     public interface PluginMetadata
    {{
       int ID {{ get;set;}
        int ID    get;set;}
    }}
MEF Key Concepts
Metadata
»Next, define the import to also load the metadata.
Access both via .NET lazy load class.

    public class Host
     public class Host
    {{
       [ImportMany]
        [ImportMany]
       public IEnumerable<Lazy<IPlugin, IPluginMetadata>> Plugins {{ get; set; }}
        public IEnumerable<Lazy<IPlugin, IPluginMetadata>> Plugins    get; set;

         void UsePlugins()
          void UsePlugins()
         {{
            foreach (var pp in Plugins)
             foreach (var    in Plugins)
            {{
                var id == p.Metadata.ID;
                 var id    p.Metadata.ID;
                var plugin == p.Value;
                 var plugin    p.Value;
            }}
         }}
    }}
What’s new in .NET 4.5?

» Support for generic types
» Multiple scopes
» Convention-based programming model that
  enables you to create parts based on rules
  rather than attributes.

   // Instead of using Export() attribute on Logger
    // Instead of using Export() attribute on Logger
   var registration == new
    var registration    new
   RegistrationBuilder();registration.ForType<Logger>().Export<ILogger>
    RegistrationBuilder();registration.ForType<Logger>().Export<ILogger>
   ();
    ();

   // Apply to all classes derived from ILogger
    // Apply to all classes derived from ILogger
   registration.ForTypesDerivedFrom<ILogger>().Export<ILogger>();
    registration.ForTypesDerivedFrom<ILogger>().Export<ILogger>();
Demo!




Give me some MEF!



     https://github.com/jasongerard/MefExample
Extending the Enterprise with MEF




    Thanks for Coming!

Brian Ritchie                          Jason Gerard
Chief Architect                        Director of Product Development
PaySpan, Inc.                          PaySpan, Inc.

Twitter: @brian_ritchie                Twitter: @thejasongerard
Email: brian.ritchie@gmail.com         Email: jason.gerard@gmail.com
Blog: http://weblog.asp.net/britchie   Blog: http://jasongerard.wordpress.com
Web: http://www.dotnetpowered.com

Más contenido relacionado

La actualidad más candente

Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
Puppet
 

La actualidad más candente (20)

KKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - AntonyKKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - Antony
 
Top 10 DevOps tools for software development
 Top 10 DevOps tools for software development  Top 10 DevOps tools for software development
Top 10 DevOps tools for software development
 
Splunk Modular Inputs / JMS Messaging Module Input
Splunk Modular Inputs / JMS Messaging Module InputSplunk Modular Inputs / JMS Messaging Module Input
Splunk Modular Inputs / JMS Messaging Module Input
 
Spring Cloud Netflix OSS
Spring Cloud Netflix OSSSpring Cloud Netflix OSS
Spring Cloud Netflix OSS
 
Navigating the Ecosystem of Pivotal Cloud Foundry Tiles
Navigating the Ecosystem of Pivotal Cloud Foundry TilesNavigating the Ecosystem of Pivotal Cloud Foundry Tiles
Navigating the Ecosystem of Pivotal Cloud Foundry Tiles
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
 
Infrastructure as Code
Infrastructure as CodeInfrastructure as Code
Infrastructure as Code
 
Github Projects Overview and IBM Streams V4.1
Github Projects Overview and IBM Streams V4.1Github Projects Overview and IBM Streams V4.1
Github Projects Overview and IBM Streams V4.1
 
Infrastructure as Code principles and practices
Infrastructure as Code  principles and practicesInfrastructure as Code  principles and practices
Infrastructure as Code principles and practices
 
DevOps for Applications in Azure Databricks: Creating Continuous Integration ...
DevOps for Applications in Azure Databricks: Creating Continuous Integration ...DevOps for Applications in Azure Databricks: Creating Continuous Integration ...
DevOps for Applications in Azure Databricks: Creating Continuous Integration ...
 
Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1
 
apidays LIVE Paris - Serverless security: how to protect what you don't see? ...
apidays LIVE Paris - Serverless security: how to protect what you don't see? ...apidays LIVE Paris - Serverless security: how to protect what you don't see? ...
apidays LIVE Paris - Serverless security: how to protect what you don't see? ...
 
Shift Left - How to improve your security with checkov before it’s going to p...
Shift Left - How to improve your security with checkov before it’s going to p...Shift Left - How to improve your security with checkov before it’s going to p...
Shift Left - How to improve your security with checkov before it’s going to p...
 
Full Stack Application Monitoring for AWS Powered by AI
Full Stack Application Monitoring for AWS Powered by AIFull Stack Application Monitoring for AWS Powered by AI
Full Stack Application Monitoring for AWS Powered by AI
 
Dynatrace - Red Hat workshop : Monolith to Microservices
Dynatrace - Red Hat workshop : Monolith to MicroservicesDynatrace - Red Hat workshop : Monolith to Microservices
Dynatrace - Red Hat workshop : Monolith to Microservices
 
Creating Event Driven Serverless Applications - Sandeep - Adobe - Serverless ...
Creating Event Driven Serverless Applications - Sandeep - Adobe - Serverless ...Creating Event Driven Serverless Applications - Sandeep - Adobe - Serverless ...
Creating Event Driven Serverless Applications - Sandeep - Adobe - Serverless ...
 
The Beginner’s Guide To Spring Cloud
The Beginner’s Guide To Spring CloudThe Beginner’s Guide To Spring Cloud
The Beginner’s Guide To Spring Cloud
 
Breaking the Monolith: Organizing Your Team to Embrace Microservices
Breaking the Monolith: Organizing Your Team to Embrace MicroservicesBreaking the Monolith: Organizing Your Team to Embrace Microservices
Breaking the Monolith: Organizing Your Team to Embrace Microservices
 
Serverless security - how to protect what you don't see?
Serverless security - how to protect what you don't see?Serverless security - how to protect what you don't see?
Serverless security - how to protect what you don't see?
 
OSMC 2021 || Open Source Application Performance Monitoring in the Enterprise
OSMC 2021 || Open Source Application Performance Monitoring in the EnterpriseOSMC 2021 || Open Source Application Performance Monitoring in the Enterprise
OSMC 2021 || Open Source Application Performance Monitoring in the Enterprise
 

Destacado

Destacado (20)

From Dev to Ops:Delivering an API to Production with Splunk
From Dev to Ops:Delivering an API to Production with SplunkFrom Dev to Ops:Delivering an API to Production with Splunk
From Dev to Ops:Delivering an API to Production with Splunk
 
CQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationCQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility Segregation
 
Siphon - Near Real Time Databus Using Kafka, Eric Boyd, Nitin Kumar
Siphon - Near Real Time Databus Using Kafka, Eric Boyd, Nitin KumarSiphon - Near Real Time Databus Using Kafka, Eric Boyd, Nitin Kumar
Siphon - Near Real Time Databus Using Kafka, Eric Boyd, Nitin Kumar
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
Building Event-Driven Systems with Apache Kafka
Building Event-Driven Systems with Apache KafkaBuilding Event-Driven Systems with Apache Kafka
Building Event-Driven Systems with Apache Kafka
 
Intro to Apache Spark
Intro to Apache SparkIntro to Apache Spark
Intro to Apache Spark
 
Alpine academy apache spark series #1 introduction to cluster computing wit...
Alpine academy apache spark series #1   introduction to cluster computing wit...Alpine academy apache spark series #1   introduction to cluster computing wit...
Alpine academy apache spark series #1 introduction to cluster computing wit...
 
Sa introduction to big data pipelining with cassandra &amp; spark west mins...
Sa introduction to big data pipelining with cassandra &amp; spark   west mins...Sa introduction to big data pipelining with cassandra &amp; spark   west mins...
Sa introduction to big data pipelining with cassandra &amp; spark west mins...
 
Rethinking Streaming Analytics For Scale
Rethinking Streaming Analytics For ScaleRethinking Streaming Analytics For Scale
Rethinking Streaming Analytics For Scale
 
How to deploy Apache Spark 
to Mesos/DCOS
How to deploy Apache Spark 
to Mesos/DCOSHow to deploy Apache Spark 
to Mesos/DCOS
How to deploy Apache Spark 
to Mesos/DCOS
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015
 
Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)
Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)
Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)
 
Reactive app using actor model & apache spark
Reactive app using actor model & apache sparkReactive app using actor model & apache spark
Reactive app using actor model & apache spark
 
Real-Time Anomaly Detection with Spark MLlib, Akka and Cassandra
Real-Time Anomaly Detection  with Spark MLlib, Akka and  CassandraReal-Time Anomaly Detection  with Spark MLlib, Akka and  Cassandra
Real-Time Anomaly Detection with Spark MLlib, Akka and Cassandra
 
Reactive dashboard’s using apache spark
Reactive dashboard’s using apache sparkReactive dashboard’s using apache spark
Reactive dashboard’s using apache spark
 
Four Things to Know About Reliable Spark Streaming with Typesafe and Databricks
Four Things to Know About Reliable Spark Streaming with Typesafe and DatabricksFour Things to Know About Reliable Spark Streaming with Typesafe and Databricks
Four Things to Know About Reliable Spark Streaming with Typesafe and Databricks
 
Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...
Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...
Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...
 
Data Science lifecycle with Apache Zeppelin and Spark by Moonsoo Lee
Data Science lifecycle with Apache Zeppelin and Spark by Moonsoo LeeData Science lifecycle with Apache Zeppelin and Spark by Moonsoo Lee
Data Science lifecycle with Apache Zeppelin and Spark by Moonsoo Lee
 
Streaming Big Data with Spark, Kafka, Cassandra, Akka & Scala (from webinar)
Streaming Big Data with Spark, Kafka, Cassandra, Akka & Scala (from webinar)Streaming Big Data with Spark, Kafka, Cassandra, Akka & Scala (from webinar)
Streaming Big Data with Spark, Kafka, Cassandra, Akka & Scala (from webinar)
 
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
 

Similar a Extending the Enterprise with MEF

MEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr WlodekMEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr Wlodek
infusiondev
 
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Ryan Baxter
 
Ui Modeling In Action With PMF, e4(XWT) And EGF
Ui Modeling In Action With PMF, e4(XWT) And EGFUi Modeling In Action With PMF, e4(XWT) And EGF
Ui Modeling In Action With PMF, e4(XWT) And EGF
BENOIT_LANGLOIS
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
 

Similar a Extending the Enterprise with MEF (20)

Building Extensible RIAs with MEF
Building Extensible RIAs with MEFBuilding Extensible RIAs with MEF
Building Extensible RIAs with MEF
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
 
OnTime Partner Webinar September 2011
OnTime Partner Webinar September 2011OnTime Partner Webinar September 2011
OnTime Partner Webinar September 2011
 
Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)
 
MEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr WlodekMEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr Wlodek
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
 
Mastering DevOps-Driven Data Integration with FME
Mastering DevOps-Driven Data Integration with FMEMastering DevOps-Driven Data Integration with FME
Mastering DevOps-Driven Data Integration with FME
 
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
 
Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)
 
Rewriting a Plugin Architecture 3 Times to Harness the API Economy
Rewriting a Plugin Architecture 3 Times to Harness the API EconomyRewriting a Plugin Architecture 3 Times to Harness the API Economy
Rewriting a Plugin Architecture 3 Times to Harness the API Economy
 
Edition of an enterprise software in PHP, feedback
Edition of an enterprise software in PHP, feedbackEdition of an enterprise software in PHP, feedback
Edition of an enterprise software in PHP, feedback
 
Simplifying RCP Update and Install
Simplifying RCP Update and InstallSimplifying RCP Update and Install
Simplifying RCP Update and Install
 
Ordina SOFTC Presentation - TFS and JAVA, better together
Ordina SOFTC Presentation - TFS and JAVA, better togetherOrdina SOFTC Presentation - TFS and JAVA, better together
Ordina SOFTC Presentation - TFS and JAVA, better together
 
Ui Modeling In Action With PMF, e4(XWT) And EGF
Ui Modeling In Action With PMF, e4(XWT) And EGFUi Modeling In Action With PMF, e4(XWT) And EGF
Ui Modeling In Action With PMF, e4(XWT) And EGF
 
DSDP Mobile Tools for Java Webinar
DSDP Mobile Tools for Java WebinarDSDP Mobile Tools for Java Webinar
DSDP Mobile Tools for Java Webinar
 
How to build and deploy app on Replit
How to build and deploy app on ReplitHow to build and deploy app on Replit
How to build and deploy app on Replit
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
What's New in Visual Studio 2010
What's New in Visual Studio 2010What's New in Visual Studio 2010
What's New in Visual Studio 2010
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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)

Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
"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 ...
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
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
 
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...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

Extending the Enterprise with MEF

  • 1. Extending the Enterprise with MEF Building extensibility into your enterprise apps with the Managed Extensibility Framework Brian Ritchie Jason Gerard Chief Architect Director of Product Development PaySpan, Inc. PaySpan, Inc. Twitter: @brian_ritchie Twitter: @thejasongerard Email: brian.ritchie@gmail.com Email: jason.gerard@gmail.com Blog: http://weblog.asp.net/britchie Blog: http://jasongerard.wordpress.com Web: http://www.dotnetpowered.com
  • 2. Who are we? Brian Ritchie Jason Gerard » Chief Architect » Director of Development » Nearly 20 years of » Nearly 15 years of development experience development experience » Developing on .NET » Only fault is that he is only since 1.0 Beta 1. one man Contributor to Mono and other open source projects
  • 3. Managed Extensibility Framework Agenda »What is MEF? »When to use MEF »Benefits of using MEF »Key Concepts »What’s new in .NET 4.5? »Demo!
  • 4. What is MEF? The Managed Extensibility Framework or MEF is a library for creating lightweight, extensible applications. »It allows application developers to discover and use extensions with no configuration required. It lets extension developers easily encapsulate code and avoid fragile hard dependencies. MEF not only allows extensions to be reused within applications, but across applications as well.
  • 5. When to use MEF? And when not to...
  • 6. When to use MEF? » You are planning to star in a zombie movie » You weren’t born in Britain but want British teeth. NO! We’re talking about MEF not METH!!
  • 7. When to use MEF? » Only if you are building an extensible UI with Silverlight or WPF applications NO! Building extensible applications is one of the key nonfunctional requirements in enterprise application development scenarios. .NET 4 for Enterprise Architects and Developers
  • 8. When to use MEF? » When you need a general purpose Dependency Injection framework or an Inversion of Control Container NO! We are not aiming for MEF to be an all-purpose IoC. The best way to think about the IoC aspects of MEF is an implementation detail. We use IoC as a pattern because it is a great way to address the problems we are looking to solve. Glenn Block Microsoft
  • 9. When to use MEF? » MEF is especially useful for large applications where injecting the dependencies between distant parts would get hard to manage as the size of the code base increases. YES! MEF is focused on extensibility. When you think of MEF look at it as an investment in taking our platform forward. Our future products and the platform will leverage MEF as a standard mechanism for adding extensibility. Imagine when you want to extend our platform in the future, you drop a DLL in the bin folder and you are done. The MEF enabled app lights up with the new extension. That's the vision for MEF. Glenn Block Microsoft
  • 10. Benefits of being a MEF user » Decomposes large systems into building blocks » Allows extensibility across teams » Turns your app into a platform
  • 11. MEF Key Concepts Ready to get hooked on MEF?
  • 12. MEF Key Concepts Exports & Imports »Exports expose contracts for functionality that can be replaced at runtime. Exports are defined in your plugin libraries. »Imports are properties that consume Exported instances. Imports are defined in your host application.
  • 13. MEF Key Concepts » Exports Decorating a class with the Export attribute [Export(typeof(IPlugin)] [Export(typeof(IPlugin)] public class MyPlugin :: IPlugin public class MyPlugin IPlugin {{ }} The interface (IPlugin) should be in Contract Assembly that can be shared between the importer (host application) and the exporter (plugin).
  • 14. MEF Key Concepts » Imports Decorating the host class with an ImportMany attribute public class Host public class Host {{ [ImportMany(typeof(IPlugin))] [ImportMany(typeof(IPlugin))] public IEnumberable<IPlugin> Plugins {{ get; set; }} public IEnumberable<IPlugin> Plugins get; set; ... ... }} The interface (IPlugin) should be in Contract Assembly that can be shared between the importer (host application) and the exporter (plugin).
  • 15. MEF Key Concepts » Imports Exports can also define imports. For example, a plugin maybe dependent on a service from the host. [Export(typeof(IPlugin)] [Export(typeof(IPlugin)] public class MyPlugin :: IPlugin public class MyPlugin IPlugin {{ [Import] [Import] IService Dependency {{ get; set; }} IService Dependency get; set; }}
  • 16. MEF Key Concepts Composition »Composition binds the Export with an Import at runtime to deliver the functionality. »A Catalog hosts the exports that need to be composed. »Types of catalogs: » Assembly Catalog » Directory Catalog » Aggregate Catalog » Type Catalog
  • 17. MEF Key Concepts Composition »Loading a catalog and binding the exports to the imports: var catalog == new DirectoryCatalog(@".plugins"); var catalog new DirectoryCatalog(@".plugins"); var container == new CompositionContainer(catalog); var container new CompositionContainer(catalog); container.ComposeParts(host); container.ComposeParts(host);
  • 18. MEF Key Concepts Composition »The Plugins collection now contains instances of all the exported types. public class Host public class Host {{ [ImportMany(typeof(IPlugin))] [ImportMany(typeof(IPlugin))] public IEnumberable<IPlugin> Plugins {{ get; set; }} public IEnumberable<IPlugin> Plugins get; set; ... ... }}
  • 19. MEF Key Concepts Metadata »Custom metadata can be attached to your exported types to provide information to the importer. »Simply add an ExportMetadata attribute which accepts a key and a value: [ExportMetadata(“ID”, 1)] [ExportMetadata(“ID”, 1)] [Export(typeof(IPlugin)] [Export(typeof(IPlugin)] public class MyPlugin :: IPlugin public class MyPlugin IPlugin {{ }}
  • 20. MEF Key Concepts Metadata »In the importer, define an Interface to access the metadata. The property and data type must match the name/value pair specified in the ExportMetadata attribute. public interface PluginMetadata public interface PluginMetadata {{ int ID {{ get;set;} int ID get;set;} }}
  • 21. MEF Key Concepts Metadata »Next, define the import to also load the metadata. Access both via .NET lazy load class. public class Host public class Host {{ [ImportMany] [ImportMany] public IEnumerable<Lazy<IPlugin, IPluginMetadata>> Plugins {{ get; set; }} public IEnumerable<Lazy<IPlugin, IPluginMetadata>> Plugins get; set; void UsePlugins() void UsePlugins() {{ foreach (var pp in Plugins) foreach (var in Plugins) {{ var id == p.Metadata.ID; var id p.Metadata.ID; var plugin == p.Value; var plugin p.Value; }} }} }}
  • 22. What’s new in .NET 4.5? » Support for generic types » Multiple scopes » Convention-based programming model that enables you to create parts based on rules rather than attributes. // Instead of using Export() attribute on Logger // Instead of using Export() attribute on Logger var registration == new var registration new RegistrationBuilder();registration.ForType<Logger>().Export<ILogger> RegistrationBuilder();registration.ForType<Logger>().Export<ILogger> (); (); // Apply to all classes derived from ILogger // Apply to all classes derived from ILogger registration.ForTypesDerivedFrom<ILogger>().Export<ILogger>(); registration.ForTypesDerivedFrom<ILogger>().Export<ILogger>();
  • 23. Demo! Give me some MEF! https://github.com/jasongerard/MefExample
  • 24. Extending the Enterprise with MEF Thanks for Coming! Brian Ritchie Jason Gerard Chief Architect Director of Product Development PaySpan, Inc. PaySpan, Inc. Twitter: @brian_ritchie Twitter: @thejasongerard Email: brian.ritchie@gmail.com Email: jason.gerard@gmail.com Blog: http://weblog.asp.net/britchie Blog: http://jasongerard.wordpress.com Web: http://www.dotnetpowered.com