SlideShare a Scribd company logo
MANAGED EXTENSIBILITY FRAMEWORK (MEF)
LarryNung
AGENDA
What is MEF
Architecture & Concept
Requirement
How to use
Demo
Reference
Q & A
WHAT IS MEF
WHAT IS MEF
 A library for creating lightweight, extensible applications.
 Discover and use extensions with no configuration required.
 Easily encapsulate code.
 Avoid fragile hard dependencies.
ARCHITECTURE & CONCEPT
ARCHITECTURE & CONCEPT
Import
Export
Part
CompositionContainer
Catalog
ARCHITECTURE & CONCEPT
REQUIREMENT
REQUIREMENT
 Assembly
 .NET 3.5+
 Silverlight 3.0+
 Reference
 System.ComponentModel.Composition.dll
 Namespace
 using System.ComponentModel.Composition;
HOW TO USE
HOW TO USE
HOW TO USE
Step3: Compose Import & Export
Step2: Decorate ExportAttribute
Step1: Decorate ImportAttribute
COMPOSE PARTS
private void Compose()
{
var catalog = new TypeCatalog(this.GetType());
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
COMPOSE PARTS
private void Compose()
{
var
catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecu
tingAssembly());
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
COMPOSE PARTS
private void Compose()
{
var catalog = new DirectoryCatalog(Environment.CurrentDirectory,
"*.dll");
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
COMPOSE PARTS
private void Compose()
{
var catalog = new ApplicationCatalog();
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
COMPOSE PARTS
private void Compose()
{
var
assemblyCatalog = new AssemblyCatalog(System.Reflection.Assembly.GetEx
ecutingAssembly());
var directoryCatalog = new DirectoryCatalog(Environment.CurrentDirectory,
"*.dll");
var catalog = new AggregateCatalog (assemblyCatalog, directoryCatalog);
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
IMPORT & EXPORT
[Import]
string message;
...
[Export]
public string Message
{
get { return "Test..."; }
}
...
IMPORT & EXPORT
[Import(“Message”)]
string message;
...
[Export(“Message”)]
public string Message
{
get { return "Test..."; }
}
…
[Export(typeof(IConfigInfo))]
public class MyClass : IConfigInfo {…
}
[Import(typeof(IConfigInfo))]
object _port1;
[Import(typeof(IConfigInfo))]
IConfigInfo _port1;
[Import(typeof(IConfigInfo))]
Lazy<IConfigInfo> _port1;
IMPORT & EXPORT
[InheritedExport(typeof(IRule))]
public interface IRule
public class RuleOne : IRule {…}
public class RuleTwo : IRule {…}
[ImportMany(typeof(IRule))]
List<IRule> _rules;
[ImportMany(typeof(IRule))]
IRule[] _rules;
[ImportMany(typeof(IRule))]
IEnumerable<IRule> _rules;
[ImportMany(typeof(IRule))]
IEnumerable<Lazy<IRule>> _rule
s;
IMPORT & EXPORT
public class MyClass
{
[ImportingConstructor]
public MyClass([Import(typeof(I
Rule))] IRule myRule)
{
_myRule = myRule;
}
}
[Export,
PartCreationPolicy(CreationPolicy.
Any)]
public class MyClass {…}
[Import]
MyClass _port1;
[Import]
MyClass _port2;
DEMO
DEMO
namespace PlugIn.Core
{
public interface IHost {
IEnumerable<IModule> Modules { get; set; }
}
}
DEMO
namespace PlugIn.Core
{
[InheritedExport] public interface IModule
{
String Name { get; }
IHost Host { get; set; }
void Execute();
}
}
DEMO
namespace Host {
public partial class MainForm : Form, IHost {
...
[ImportMany] public IEnumerable<IModule> Modules { get; set; }
public MainForm() {
InitializeComponent();
var catalog = new DirectoryCatalog(Environment.CurrentDirectory, "*.dll");
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
foreach (IModule module in Modules) {
module.Host = this;
模組MToolStripMenuItem.DropDownItems.Add(module.Name, null,
Module_Click).Tag = module;
}
}
...
}
}
DEMO
REFERENCE
27
REFERENCE
 [C#]MEF開發系列 - Managed Extensibility Framework(MEF)的概念與
簡介 - Level Up- 點部落
 http://www.dotblogs.com.tw/larrynung/archive/2012/12/11/85576.aspx?fid=72
390
 Managed Extensibility Framework - Home
 http://mef.codeplex.com/
 Managed Extensibility Framework - Wikipedia, the free encyclopedia
 http://en.wikipedia.org/wiki/Managed_Extensibility_Framework
REFERENCE
 Managed Extensibility Framework - Building Composable Apps
in .NET 4 with the Managed Extensibility Framework
 https://msdn.microsoft.com/en-us/magazine/ee291628.aspx
 [VS2010 Online]Managed Extensibility Framework in Visual Studio
2010 -- (1) - Response.Write("Hello LOLOTA")- 點部落
 http://www.dotblogs.com.tw/lolota/archive/2010/03/03/13860.aspx
 Managed Extensibility Framework (MEF)
 https://msdn.microsoft.com/zh-tw/library/dd460648(v=vs.110).aspx
Q&A
30
QUESTION & ANSWER
31

More Related Content

PPT
Managed Extensibility Framework (MEF)
PDF
JDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek Piotrowski
PDF
Automated Xcode 7 UI Testing
PDF
How to capture a variable in C# and not to shoot yourself in the foot
PPTX
Angular 5 presentation for beginners
PPTX
C# Security Testing and Debugging
PPTX
MEF Deep Dive by Piotr Wlodek
PPT
Mef 12 step program
Managed Extensibility Framework (MEF)
JDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek Piotrowski
Automated Xcode 7 UI Testing
How to capture a variable in C# and not to shoot yourself in the foot
Angular 5 presentation for beginners
C# Security Testing and Debugging
MEF Deep Dive by Piotr Wlodek
Mef 12 step program

Similar to Managed extensibility framework (20)

PPT
Extending the Enterprise with MEF
PPTX
Managed Extensibility Framework or Effective Development of Scalable Applicat...
PPTX
PDF
Managed Extensibility Framework
PPTX
Building extensible application using MEF
PPTX
When MEF meets Silverlight
PPTX
MEF in Silverlight 4 - a guided tour
PPTX
Building Extensible RIAs with MEF
PPTX
WPF and Prism 4.1 Workshop at BASTA Austria
PPTX
Microsoft Managed Extensibility Framework
PPT
Mef with meta data and lazy loading
PPTX
Visual Studio 2010 and .NET Framework 4.0 Overview
PDF
Mike Taulty DevDays 2010 Silverlight MEF
PPTX
Plugin architecture (Extensible Application Architecture)
PPTX
Overview Of .Net 4.0 Sanjay Vyas
PPTX
Introduction to the Managed Extensibility Framework in Silverlight
PDF
Smart Client Development
PDF
C# .NET Developer Portfolio
KEY
MEFilicious Applications
PPT
Extensibility - Software That Survives - Miguel A. Castro
Extending the Enterprise with MEF
Managed Extensibility Framework or Effective Development of Scalable Applicat...
Managed Extensibility Framework
Building extensible application using MEF
When MEF meets Silverlight
MEF in Silverlight 4 - a guided tour
Building Extensible RIAs with MEF
WPF and Prism 4.1 Workshop at BASTA Austria
Microsoft Managed Extensibility Framework
Mef with meta data and lazy loading
Visual Studio 2010 and .NET Framework 4.0 Overview
Mike Taulty DevDays 2010 Silverlight MEF
Plugin architecture (Extensible Application Architecture)
Overview Of .Net 4.0 Sanjay Vyas
Introduction to the Managed Extensibility Framework in Silverlight
Smart Client Development
C# .NET Developer Portfolio
MEFilicious Applications
Extensibility - Software That Survives - Miguel A. Castro
Ad

More from Larry Nung (20)

PPTX
Ansible - simple it automation
PPTX
sonarwhal - a linting tool for the web
PPTX
LiteDB - A .NET NoSQL Document Store in a single data file
PPTX
PL/SQL & SQL CODING GUIDELINES – Part 8
PPTX
MessagePack - An efficient binary serialization format
PPTX
PL/SQL & SQL CODING GUIDELINES – Part 7
PPTX
BenchmarkDotNet - Powerful .NET library for benchmarking
PPTX
PLSQL Coding Guidelines - Part 6
PPTX
SonarQube - The leading platform for Continuous Code Quality
PPTX
Visual studio 2017
PPTX
Web deploy command line
PPTX
Web deploy
PPTX
SikuliX
PPTX
Topshelf - An easy service hosting framework for building Windows services us...
PPTX
Common.logging
PPTX
protobuf-net - Protocol Buffers library for idiomatic .NET
PPTX
PL/SQL & SQL CODING GUIDELINES – Part 5
PPTX
Regular expression
PPTX
PL/SQL & SQL CODING GUIDELINES – Part 4
PPTX
Fx.configuration
Ansible - simple it automation
sonarwhal - a linting tool for the web
LiteDB - A .NET NoSQL Document Store in a single data file
PL/SQL & SQL CODING GUIDELINES – Part 8
MessagePack - An efficient binary serialization format
PL/SQL & SQL CODING GUIDELINES – Part 7
BenchmarkDotNet - Powerful .NET library for benchmarking
PLSQL Coding Guidelines - Part 6
SonarQube - The leading platform for Continuous Code Quality
Visual studio 2017
Web deploy command line
Web deploy
SikuliX
Topshelf - An easy service hosting framework for building Windows services us...
Common.logging
protobuf-net - Protocol Buffers library for idiomatic .NET
PL/SQL & SQL CODING GUIDELINES – Part 5
Regular expression
PL/SQL & SQL CODING GUIDELINES – Part 4
Fx.configuration
Ad

Recently uploaded (20)

PPT
Chapter four Project-Preparation material
PDF
Reconciliation AND MEMORANDUM RECONCILATION
PDF
COST SHEET- Tender and Quotation unit 2.pdf
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PPTX
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
PPTX
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
PPTX
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
PDF
Laughter Yoga Basic Learning Workshop Manual
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
PDF
Ôn tập tiếng anh trong kinh doanh nâng cao
PPTX
Principles of Marketing, Industrial, Consumers,
PDF
How to Get Funding for Your Trucking Business
PPTX
HR Introduction Slide (1).pptx on hr intro
PDF
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PPTX
Amazon (Business Studies) management studies
PDF
Types of control:Qualitative vs Quantitative
PDF
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
Chapter four Project-Preparation material
Reconciliation AND MEMORANDUM RECONCILATION
COST SHEET- Tender and Quotation unit 2.pdf
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
Power and position in leadershipDOC-20250808-WA0011..pdf
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
Laughter Yoga Basic Learning Workshop Manual
ICG2025_ICG 6th steering committee 30-8-24.pptx
Ôn tập tiếng anh trong kinh doanh nâng cao
Principles of Marketing, Industrial, Consumers,
How to Get Funding for Your Trucking Business
HR Introduction Slide (1).pptx on hr intro
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
340036916-American-Literature-Literary-Period-Overview.ppt
Amazon (Business Studies) management studies
Types of control:Qualitative vs Quantitative
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise

Managed extensibility framework

  • 2. AGENDA What is MEF Architecture & Concept Requirement How to use Demo Reference Q & A
  • 4. WHAT IS MEF  A library for creating lightweight, extensible applications.  Discover and use extensions with no configuration required.  Easily encapsulate code.  Avoid fragile hard dependencies.
  • 9. REQUIREMENT  Assembly  .NET 3.5+  Silverlight 3.0+  Reference  System.ComponentModel.Composition.dll  Namespace  using System.ComponentModel.Composition;
  • 12. HOW TO USE Step3: Compose Import & Export Step2: Decorate ExportAttribute Step1: Decorate ImportAttribute
  • 13. COMPOSE PARTS private void Compose() { var catalog = new TypeCatalog(this.GetType()); var container = new CompositionContainer(catalog); container.ComposeParts(this); }
  • 14. COMPOSE PARTS private void Compose() { var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecu tingAssembly()); var container = new CompositionContainer(catalog); container.ComposeParts(this); }
  • 15. COMPOSE PARTS private void Compose() { var catalog = new DirectoryCatalog(Environment.CurrentDirectory, "*.dll"); var container = new CompositionContainer(catalog); container.ComposeParts(this); }
  • 16. COMPOSE PARTS private void Compose() { var catalog = new ApplicationCatalog(); var container = new CompositionContainer(catalog); container.ComposeParts(this); }
  • 17. COMPOSE PARTS private void Compose() { var assemblyCatalog = new AssemblyCatalog(System.Reflection.Assembly.GetEx ecutingAssembly()); var directoryCatalog = new DirectoryCatalog(Environment.CurrentDirectory, "*.dll"); var catalog = new AggregateCatalog (assemblyCatalog, directoryCatalog); var container = new CompositionContainer(catalog); container.ComposeParts(this); }
  • 18. IMPORT & EXPORT [Import] string message; ... [Export] public string Message { get { return "Test..."; } } ...
  • 19. IMPORT & EXPORT [Import(“Message”)] string message; ... [Export(“Message”)] public string Message { get { return "Test..."; } } … [Export(typeof(IConfigInfo))] public class MyClass : IConfigInfo {… } [Import(typeof(IConfigInfo))] object _port1; [Import(typeof(IConfigInfo))] IConfigInfo _port1; [Import(typeof(IConfigInfo))] Lazy<IConfigInfo> _port1;
  • 20. IMPORT & EXPORT [InheritedExport(typeof(IRule))] public interface IRule public class RuleOne : IRule {…} public class RuleTwo : IRule {…} [ImportMany(typeof(IRule))] List<IRule> _rules; [ImportMany(typeof(IRule))] IRule[] _rules; [ImportMany(typeof(IRule))] IEnumerable<IRule> _rules; [ImportMany(typeof(IRule))] IEnumerable<Lazy<IRule>> _rule s;
  • 21. IMPORT & EXPORT public class MyClass { [ImportingConstructor] public MyClass([Import(typeof(I Rule))] IRule myRule) { _myRule = myRule; } } [Export, PartCreationPolicy(CreationPolicy. Any)] public class MyClass {…} [Import] MyClass _port1; [Import] MyClass _port2;
  • 22. DEMO
  • 23. DEMO namespace PlugIn.Core { public interface IHost { IEnumerable<IModule> Modules { get; set; } } }
  • 24. DEMO namespace PlugIn.Core { [InheritedExport] public interface IModule { String Name { get; } IHost Host { get; set; } void Execute(); } }
  • 25. DEMO namespace Host { public partial class MainForm : Form, IHost { ... [ImportMany] public IEnumerable<IModule> Modules { get; set; } public MainForm() { InitializeComponent(); var catalog = new DirectoryCatalog(Environment.CurrentDirectory, "*.dll"); var container = new CompositionContainer(catalog); container.ComposeParts(this); foreach (IModule module in Modules) { module.Host = this; 模組MToolStripMenuItem.DropDownItems.Add(module.Name, null, Module_Click).Tag = module; } } ... } }
  • 26. DEMO
  • 28. REFERENCE  [C#]MEF開發系列 - Managed Extensibility Framework(MEF)的概念與 簡介 - Level Up- 點部落  http://www.dotblogs.com.tw/larrynung/archive/2012/12/11/85576.aspx?fid=72 390  Managed Extensibility Framework - Home  http://mef.codeplex.com/  Managed Extensibility Framework - Wikipedia, the free encyclopedia  http://en.wikipedia.org/wiki/Managed_Extensibility_Framework
  • 29. REFERENCE  Managed Extensibility Framework - Building Composable Apps in .NET 4 with the Managed Extensibility Framework  https://msdn.microsoft.com/en-us/magazine/ee291628.aspx  [VS2010 Online]Managed Extensibility Framework in Visual Studio 2010 -- (1) - Response.Write("Hello LOLOTA")- 點部落  http://www.dotblogs.com.tw/lolota/archive/2010/03/03/13860.aspx  Managed Extensibility Framework (MEF)  https://msdn.microsoft.com/zh-tw/library/dd460648(v=vs.110).aspx

Editor's Notes

  • #5: Managed Extensibility Framework 或 MEF 是用於建立輕量型可擴充應用程式的程式庫。 它可讓應用程式開發人員無需任何設定,即可探索並使用擴充功能。 它也可讓擴充功能開發人員輕易地封裝程式碼並避免出現不牢固的硬式相依性。 透過 MEF,不僅可在應用程式內重複使用擴充功能,也可跨應用程式重複使用擴充功能。 主要側重在 探索性、擴充性、與可移植性
  • #7: Composable part 是composable unit,也就是最小的組成單位,可以提供服務給其他組件使用(擴充功能)或是操作其他組件提供的服務(擴充點)。 Export 是指提供的服務,也就是我們所說的擴充功能。透過ExportAttribute來設定。 Import 是指所使用的服務,也就是我們所說的擴充點。透過ImportAttribute來設定。 Composition Container 是組合容器,會去mapping import跟export、組合Composable part。 Catalog 主要是用來探索Composable part用的,可從型別、組件 (Assembly) 或目錄 (Directory)探索到Composable part。