Managed Extensibility Framework

1,688 views
1,476 views

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,688
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
56
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Managed Extensibility 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 extending applications 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 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 Create parts Dispose parts
  15. 15. Part Sample Typed Contract
  16. 16. Part Sample Named Contract
  17. 17. Part Sample 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 from Container 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.

×