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

推荐订阅源

Y
Y Combinator Blog
S
SegmentFault 最新的问题
Engineering at Meta
Engineering at Meta
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google DeepMind News
Google DeepMind News
博客园_首页
云风的 BLOG
云风的 BLOG
月光博客
月光博客
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
D
Docker
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
博客园 - 叶小钗
Martin Fowler
Martin Fowler
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - 一一九九

【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)"