Managed Extensibility Framework or Effective Development of Scalable Applications with .NET...
-
Upload
softserve -
Category
Economy & Finance
-
view
1.186 -
download
2
description
Transcript of Managed Extensibility Framework or Effective Development of Scalable Applications with .NET...
![Page 1: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/1.jpg)
Volodymyr Voytyshyn03/17/2012
ManagedExtensibility Framework
Effective Development of Scalable Applications with .NET
![Page 2: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/2.jpg)
Agenda
What is MEF?
Key concepts and features
How to implement …?
What’s new in MEF 2.0?
![Page 3: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/3.jpg)
WHAT IS MEF?
![Page 4: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/4.jpg)
The Problem
No unified approach
for extension application in runtime
![Page 5: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/5.jpg)
The Solution
MEF – Managed Extensibility Framework
Simply
Reliably
Unified
![Page 6: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/6.jpg)
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)
![Page 7: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/7.jpg)
MEF focuses on…
Extending of ready-made applications by plugins
Plugin 1 Plugin 2
Application
?
![Page 8: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/8.jpg)
How about reflection?
System.Reflection.*Assembly.Load()
…
![Page 9: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/9.jpg)
As a result…
The next unique solution
Not reusable components
Extending by 3rd parties plugins
![Page 10: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/10.jpg)
KEY CONCEPTS AND FEATURES
![Page 11: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/11.jpg)
Composable Part
Part
Export
Import
![Page 12: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/12.jpg)
More Composable Parts
ImportImport
ExportExport
![Page 13: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/13.jpg)
The Main Idea - Composition
![Page 14: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/14.jpg)
Composition Container
Composition Container
Creates parts
Dispose parts
Compose parts
![Page 15: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/15.jpg)
The Part
Typed Contract
![Page 16: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/16.jpg)
The Part
Named Contract
![Page 17: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/17.jpg)
The Part
Extension Point
Extension Point
![Page 18: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/18.jpg)
Composition of Parts
Compositionof parts
![Page 19: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/19.jpg)
Don’t forget…
Add reference
System.ComponentModel.Composition.dll
Using namespaces
System.ComponentModel.Composition.*
![Page 20: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/20.jpg)
More About Import
![Page 21: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/21.jpg)
Export Metadata
Key
Value
![Page 22: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/22.jpg)
Getting Exports
Contract
Returns Lazy
![Page 23: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/23.jpg)
Creation Policy
Default value
Shared
NonShared
Any
Shared == Singleton
Any & Any == Shared
![Page 24: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/24.jpg)
References to Parts
Container keeps reference to part if:
– Part is marked as Shared
– Part implements IDisposable
– One or more imports allow Recomposition
![Page 25: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/25.jpg)
Disposing Composition Container
Dispose parts which implement IDisposable
Reference to parts will be cleaned up
Lazy exports won’t work
![Page 26: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/26.jpg)
Catalog
Catalog
CompositionContainer
Discover parts
Compose parts
![Page 27: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/27.jpg)
Catalog Types
Assembly Catalog
Directory Catalog
Type Catalog
Aggregate Catalog
Deployment Catalog(only for Silverlight)
![Page 28: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/28.jpg)
Recomposition Support
Assembly Catalog
Directory Catalog Refresh()
Type Catalog
Aggregate Catalog auto
Deployment Catalog auto
![Page 29: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/29.jpg)
![Page 30: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/30.jpg)
HOW TO IMPLEMENT… ?
![Page 31: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/31.jpg)
MEF-based Dependency Injection
CompositionContainer
Service Locator
TPart Resolve<TPart>()
void Release<TPart>(TPart part) CommonService Locator
MEF Adapter
![Page 32: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/32.jpg)
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)
![Page 33: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/33.jpg)
Plugin-based Desktop Application
Most Useful Tool
Directory Catalog
Composition Container
File System Watcher
Plugins Folder
Trackchanges
Refresh()
![Page 34: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/34.jpg)
Plugin-based Desktop Application
Allow parts recomposition
Assemblies shadow copy
! Plugin assemblycan not be unloaded in runtime
![Page 35: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/35.jpg)
Plugin-based ASP.NET MVC Application
ASP.NET MVC Application
Models Views Plugins
Models Views
Controlle
rs
Controlle
rs
![Page 36: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/36.jpg)
Plugin-based ASP.NET MVC Application
Integrate MEF into ControllerFactory
MEF-based DependencyResolver
? Compile razor view to separate assembly
![Page 37: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/37.jpg)
WHAT’S NEW IN MEF 2.0?
![Page 38: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/38.jpg)
MEF 2.0 and .NET 4.5
![Page 39: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/39.jpg)
Open Generic Parts
Any type
![Page 40: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/40.jpg)
Convention-based Part Registration
![Page 41: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/41.jpg)
Composition Scoping Enhancements
Global Scope
Request Scope
Composition Container
Logger
Customer Controller
Customer RepositoryFor each request
Once
![Page 42: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/42.jpg)
Composition Provider for ASP.NET MVC Registering in composition container:
– Controllers– Action filters– Model binders
Constructor injection for controllers
![Page 43: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/43.jpg)
ASP.NET MVC: processing of parts
Naming convention
Contract identification
![Page 44: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/44.jpg)
Composition Provider for ASP.NET MVC Composition scopes
– Request scope
– Application scope
![Page 45: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/45.jpg)
MEF Offers…
Easy way for:
Composition independent components
Extending without recompiling
Delivering 3rd party plugins
![Page 46: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/46.jpg)
Ask your question…
![Page 47: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/47.jpg)
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)
![Page 48: Managed Extensibility Framework or Effective Development of Scalable Applications with .NET Framework](https://reader034.fdocuments.us/reader034/viewer/2022052307/55496b42b4c905dd558b4df9/html5/thumbnails/48.jpg)
Thank You!
Copyright © 2011 SoftServe, Inc.
Contacts
Volodymyr Voytyshyn5 Knyahyni Olhy Str., Rivne 33000, Ukraine
Tel: +38(066) 41 83 509
E-mail: [email protected]@gmail.com
Skype: voytyshin