KEY Concepts
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:
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)"