I've used MEF before, but am having problems now with the newer implementation. I'm exporting objects inheriting from a base class, that has the [InheritedExport] attribute, and am trying to get them imported.
Before, I would just have an array property with [ImportMany(typeof(mytype))], and use CompositionInitializer.SatisfyImports(this) to get the imports to work, but now I have two problems:
1) The exports are in a different, referenced assembly; 2) CompositionInitializer doesn't seem to exist in the newer MEF in the 4.5 framework.
I'm trying to create an AggregateCatalog to solve problem #1, but have no idea where to go from here.
In the end, I'm trying to import a collection that can be used by the entire WPF app, if anyone can give me any assistance in suggesting an overall solution.
As you say, you will need the
AggregateCatalog
to aggregate a number of catalogs. Usually you will need one catalog for each assembly that contains a part (export/import). This means that you will have to use the AssemblyCatalog class for each one of theses loaded assemblies. You can access the loaded assemblies through one of the types that they contain. Here's a small example that adds a couple of AssemblyCatalogs to an AggregateCatalog.For more information on catalogs you can read this small article.
This is only available on
Silverlight
. OnWPF
you will have to create a CompositionContainer and use itsSatisfyImports
method.