Managed            Extensibility FrameworkEffective Development of Scalable Applications with .NET                        ...
Agenda What is MEF? Key concepts and features How to implement …? What’s new in MEF 2.0?
WHAT IS MEF?
The Problem          No unified approach   for extension application in runtime
The Solution MEF – Managed Extensibility Framework  Simply  Reliably  Unified
MEF Project Official Site      http://mef.codeplex.com Developer          Microsoft Started            26.08.2008 Lice...
MEF focuses on… Extending of ready-made applications by plugins                  Application      Plugin 1       Plugin 2
How about reflection?       System.Reflection.*         Assembly.Load()                …
As a result… The next unique solution Not reusable components Extending by 3rd parties  plugins
KEY CONCEPTS AND FEATURES
Composable Part                         Export                  Part      Import
More Composable Parts  Import   Import                        Export                         Export
The Main Idea - Composition
Composition Container                        Composition Container Compose parts                     Creates parts      ...
The Part           Typed Contract
The Part           Named Contract
The Part           Extension             Point           Extension             Point
Composition of Parts  Composition    of parts
Don’t forget… Add referenceSystem.ComponentModel.Composition.dll Using namespaces System.ComponentModel.Composition.*
More About Import
Export Metadata              Key                    Value
Getting Exports                        Contract         Returns Lazy
Creation Policy          Shared                                   Default          NonShared                value       ...
References to Parts Container keeps reference to part if:  – Part is marked as Shared  – Part implements IDisposable  – O...
Disposing Composition Container Dispose parts which implement IDisposable Reference to parts will be cleaned up Lazy ex...
Catalog            Composition             Container                          Compose                            parts Dis...
Catalog Types        Assembly Catalog        Directory Catalog        Type Catalog        Aggregate Catalog        Deploym...
Recomposition Support Assembly Catalog Directory Catalog     Refresh() Type Catalog Aggregate Catalog     auto Deploy...
HOW TO IMPLEMENT… ?
MEF-based Dependency Injection       Service Locator  TPart Resolve<TPart>()  void Release<TPart>(TPart part)      Common ...
MEF vs IoC+ Ease of programming+ Resolves dependencies between components+ Automatic component discovery+ Can compose type...
Plugin-based Desktop Application      Most Useful Tool             Composition              Container             Plugins ...
Plugin-based Desktop Application Allow parts recomposition Assemblies shadow copy! Plugin assembly  can not be unloaded ...
Plugin-based ASP.NET MVC Application           ASP.NET MVC Application Models   Views                  Plugins            ...
Plugin-based ASP.NET MVC ApplicationIntegrate MEF into ControllerFactoryMEF-based DependencyResolver? Compile razor view...
WHAT’S NEW IN MEF 2.0?
MEF 2.0 and .NET 4.5
Open Generic Parts                     Any type
Convention-based Part Registration
Composition Scoping Enhancements   Once                            Global Scope                                      Logge...
Composition Provider for ASP.NET MVC Registering in composition container:   – Controllers   – Action filters   – Model b...
ASP.NET MVC: processing of parts               Naming             convention              Contract            identification
Composition Provider for ASP.NET MVC Composition scopes  – Request scope  – Application scope
MEF Offers… Easy way for:   Composition independent components   Extending without recompiling   Delivering 3rd party ...
Ask your question…
Useful Sources MEF Project (official site) Managed Extensibility Framework Overview (msdn) Building Composable Apps in ...
Contacts                                   Volodymyr Voytyshyn                                   5 Knyahyni Olhy Str., Riv...
Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework
Upcoming SlideShare
Loading in …5
×

Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework

1,837 views

Published on

by Volodymyr Voytyshyn

Published in: Economy & Finance, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,837
On SlideShare
0
From Embeds
0
Number of Embeds
236
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework

  1. 1. Managed Extensibility FrameworkEffective Development of Scalable Applications with .NET Volodymyr Voytyshyn 03/17/2012
  2. 2. Agenda What is MEF? Key concepts and features How to implement …? What’s new in MEF 2.0?
  3. 3. WHAT IS MEF?
  4. 4. The Problem No unified approach for extension application in runtime
  5. 5. The Solution MEF – Managed Extensibility Framework  Simply  Reliably  Unified
  6. 6. MEF Project Official Site http://mef.codeplex.com Developer Microsoft Started 26.08.2008 License MS Public License (open source) Last stable release MEF 1 / 12.04.2010 (included into .NET 4.0)
  7. 7. MEF focuses on… Extending of ready-made applications by plugins Application Plugin 1 Plugin 2
  8. 8. How about reflection? System.Reflection.* Assembly.Load() …
  9. 9. As a result… The next unique solution Not reusable components Extending by 3rd parties plugins
  10. 10. KEY CONCEPTS AND FEATURES
  11. 11. Composable Part Export Part Import
  12. 12. More Composable Parts Import Import Export Export
  13. 13. The Main Idea - Composition
  14. 14. Composition Container Composition Container Compose parts  Creates parts  Dispose parts
  15. 15. The Part Typed Contract
  16. 16. The Part Named Contract
  17. 17. The Part Extension Point Extension Point
  18. 18. Composition of Parts Composition of parts
  19. 19. Don’t forget… Add referenceSystem.ComponentModel.Composition.dll Using namespaces System.ComponentModel.Composition.*
  20. 20. More About Import
  21. 21. Export Metadata Key Value
  22. 22. Getting Exports Contract Returns Lazy
  23. 23. Creation Policy  Shared Default  NonShared value  Any  Any & Any == Shared  Shared == Singleton
  24. 24. References to Parts Container keeps reference to part if: – Part is marked as Shared – Part implements IDisposable – One or more imports allow Recomposition
  25. 25. Disposing Composition Container Dispose parts which implement IDisposable Reference to parts will be cleaned up Lazy exports won’t work
  26. 26. Catalog Composition Container Compose parts Discover parts Catalog
  27. 27. Catalog Types Assembly Catalog Directory Catalog Type Catalog Aggregate Catalog Deployment Catalog (only for Silverlight)
  28. 28. Recomposition Support Assembly Catalog Directory Catalog Refresh() Type Catalog Aggregate Catalog auto Deployment Catalog auto
  29. 29. HOW TO IMPLEMENT… ?
  30. 30. MEF-based Dependency Injection Service Locator TPart Resolve<TPart>() void Release<TPart>(TPart part) Common Service Locator Composition Container MEF Adapter
  31. 31. MEF vs IoC+ Ease of programming+ Resolves dependencies between components+ Automatic component discovery+ Can compose types, fields, props and methods- Slower than IoC containers- Poor component lifetime management- No component separation (separate appdomain, process)
  32. 32. Plugin-based Desktop Application Most Useful Tool Composition Container Plugins Folder Directory Catalog Refresh() Track File System Watcher changes
  33. 33. Plugin-based Desktop Application Allow parts recomposition Assemblies shadow copy! Plugin assembly can not be unloaded in runtime
  34. 34. Plugin-based ASP.NET MVC Application ASP.NET MVC Application Models Views Plugins Models Views
  35. 35. Plugin-based ASP.NET MVC ApplicationIntegrate MEF into ControllerFactoryMEF-based DependencyResolver? Compile razor view to separate assembly
  36. 36. WHAT’S NEW IN MEF 2.0?
  37. 37. MEF 2.0 and .NET 4.5
  38. 38. Open Generic Parts Any type
  39. 39. Convention-based Part Registration
  40. 40. Composition Scoping Enhancements Once Global Scope Logger Composition Container Request Scope Customer Controller For each request Customer Repository
  41. 41. Composition Provider for ASP.NET MVC Registering in composition container: – Controllers – Action filters – Model binders Constructor injection for controllers
  42. 42. ASP.NET MVC: processing of parts Naming convention Contract identification
  43. 43. Composition Provider for ASP.NET MVC Composition scopes – Request scope – Application scope
  44. 44. MEF Offers… Easy way for:  Composition independent components  Extending without recompiling  Delivering 3rd party plugins
  45. 45. Ask your question…
  46. 46. Useful Sources MEF Project (official site) Managed Extensibility Framework Overview (msdn) Building Composable Apps in .NET 4 with MEF (msdn) BCL Team Blog (msdn) Book of MEF (habrahabr)
  47. 47. Contacts Volodymyr Voytyshyn 5 Knyahyni Olhy Str., Rivne 33000, Ukraine Tel: +38(066) 41 83 509 E-mail: vvoit@softserveinc.com voytyshyn@gmail.com Skype: voytyshin Thank You!Copyright © 2011 SoftServe, Inc.

×