Introduce to MEF (Study)- one
2012-03-19 22:36
141 查看
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:
[/code]
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
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)"
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;
[code]
var Catalog = new AggreagteCatalog(new DirectCatalog("."), new AssemblyCatalog(Assembly.GetExectuingAssembly());
var Container = new CompositonContainer(Catalog);
var window = Container.GetExportedValue<CashMaker>();
[/code]
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
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)"
相关文章推荐
- hibernate OneToOne hql多表查询
- Maven之Unable to load the mojo 'resources' (or one of its required components)
- To-Study Course List
- Hibernate 关联映射one-to-one
- [JavaScript] Use `+` opertor to add one string and one number
- Hibernate OneToOne mapping primary key [Annotation]
- Expected one result (or null) to be returned by selectOne(), but found: 2
- Hibernate-one-to-Many详解
- @OneToMany三种设置方式详解
- How to know whether the attribute belongs to one types of productin Magento?
- hibernate OneToOne(Annotation)
- HowTo: ListView, Adapter, getView and different list items’ layouts in one ListView
- 【转】Hibernate one-to-many / many-to-one关系映射
- ubuntu更新时出现错误 E: Some index files failed to download, they have been ignored, or old ones used inst
- Error:Project has no default.properties file! Edit the project properties to set one
- 近十年one-to-one最短路算法研究整理
- Java Conversion from String to bytes is not one-one?
- JPA之OneToOne映射的示例
- 【FAQ Fix】 JPA Double insert with @OneToMany and CASCADE.ALL
- BAPI to Copy Materials from one Plant to Another