惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
Visual Studio Blog
G
Google Developers Blog
V
V2EX
The Register - Security
The Register - Security
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
S
SegmentFault 最新的问题
博客园 - Franky
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
C
Check Point Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
F
Fortinet All Blogs
Jina AI
Jina AI
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
B
Blog
L
LangChain Blog
月光博客
月光博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
GbyAI
GbyAI

博客园 - 一一九九

【wpf】AnimatedTabControl 如何显示内容 [wpf]设置Application的ICO Error: does not contain a static 'Main' method suitable for an entry point [wpf] Can you outline a story-driven process with Concordion? Your First Concordion.Net Project (Part 5)-Running Specs with Gallio Your First Concordion.Net Project (Part 4)-More Specifications! Your First Concordion.Net Project (Part 3)-Adding Specifications Your First Concordion.Net Project (Part 2)-Setting Up Visual Studio Your First Concordion.NET Project (Part 1)-What is Concordion.Net? [Specification by Example][ch5 Deriving scope from goals]-[读书笔记]-[4] [Specification by Example][ch5 Deriving scope from goals]-[读书笔记]-[3] [Specification by Example][ch5 Deriving scope from goals]-[读书笔记]-[2] [Specification by Example][ch5 Deriving scope from goals]-[读书笔记]-[1] [Specification by Example][ch4 Initiation the changes]-[读书笔记] [Specification by Example][ch3 Living documentation]-[读书笔记] [Specification by Example][ch2 key process patterns]-[读书笔记] [Specification by Example][ch1 key benefits]-[读书笔记] Binding Resource
Introduce to MEF (Study)- one
一一九九 · 2012-03-19 · via 博客园 - 一一九九

2012-03-19 22:36  一一九九  阅读(258)  评论()    收藏  举报

KEY  Concepts

  • Composition  is the practice of combining serveral objects with discrete  functionality into one or more complex objects.
  • ComposableParts are the key building blocks of MEF.  ComposableParts enable applications to expose and consume component extensions via Exports and Imports.
  • Contracts are the avenue for communication between export and import components. A Contract is normally implemented via an interface class. Contracts enable MEF ComposableParts to avoid dependencies or tight coupling with other components.
  • Conditonal Binding allows loading of components, which meet specific metadata criteria.

Assembly: System.ComponentModel.Composition

create host:

using System.ComponentModel.Composition.Hosting;
 
var Catalog = new AggreagteCatalog(new DirectCatalog("."),  new AssemblyCatalog(Assembly.GetExectuingAssembly());
 
var Container = new CompositonContainer(Catalog);
 
var window = Container.GetExportedValue<CashMaker>();

MEF’s container interacts with Catalogs to have access to Composable Parts. The container itself resolvers a part’s dependencies and exposes Exports to the outside world. you are free to add composable parts instances directly to the container if you wish.

There are different kinds of Catalogs, which are able to discover parts on different ways.  the full list of catalogs available on MEF is:

  • Assembly Catalog: Discovers the different parts on a specific assembly.
  • Directory Catalog:  Discovers parts inside the assembies on a specific directory.
  • Aggregate Catalog: Allows use more than one catalog combing them/
  • Type Catalog: Looks inside the assemblies for specific types.

you can import collections with the ImportMany attribute . This means that all instances of the specific contract will be imported from the Container. MEF parts can also support recomposition. This means that as new exports become avaiable in the container, collecitons are automatically updated with the new Set.

once MEF completes the CarQueries colleciton import proces, you want your application to be notified and so it can take particular action. To do this, make the CashMaker class to implement the IPartImportsSatisfiedNotification interface as shown in the following code.

1. ContosoAutomotive.Woodgrove project and select Properties. In the Properties page, select the Build Events tab (for C# projects) or select the Compile tab and press the Build Events… button (for Visual Basic projects) and enter the following value in the Post-build event command line:

Post-Build Command

copy "$(TargetPath)" "$(SolutionDir)ContosoAutomotive\bin\$(ConfigurationName)"