I've been trying to figure this for a few days now, with no luck.
I'm trying to use the [ImportMany] to import from a directory full of DLL's with exports of type IEditorSystem, that have custom metadate of type IEditorSystemMetadata. I'd like to get the metadata first, and push it out to some textboxs etc so the user can choose which EditorSystem to use, and when selected, load that system...
I've been following examples as best as I can, here's what I have so far.
[ImportMany]
public ObservableCollection<Lazy<IEditorSystem, IEditorSystemMetadata>> EditorSystemList
This is what it should be importing:
[Export(typeof(IEditorSystem))]
[SignalSystemData("Very Very Long Name", "Short Name")]
public class MyEditorSystem: IEditorSystem
{
public MyEditorSystem()
{
}
}
and the startup:
AggregateCatalog Catalog = new AggregateCatalog(
new DirectoryCatalog(@".\EditorSystems"),
new AssemblyCatalog(Assembly.GetExecutingAssembly()));
CompositionContainer Container = new CompositionContainer(Catalog);
Container.ComposeParts(this);
I can see in the Catalog.Parts both the MyEditorSystem and the viewmodel that has the ImportMany, but EditorSystemList never gets populated. I get no Composition errors.
I thought it might have something to do with the Lazy<>, so i tried
public ObservableCollection<IEditorSystem> EditorSystemList
No luck either.
The only complication I can think of is that I'm using Cinch, which uses MEFedMVVM, which also uses MEF. I don't think it interferes, but I'm not really sure.
I figure I'm doing it wrong, can anyone make sense of this?
Update:
Implement a new IComposer, with exactly the catalog you need.
ImportMany is still failing though, but only when I try to import metadata with it. The metadata is just a couple of strings, and as far as I am able to determine, follows the examples.
FINALLY found the cause: The implementations of IEditorSystem are in a seperate DLL, as noted before. However, any new builds of the dll are not copied to the output subdir of the main project. I had copied the first one manually, and forgot to add a post-build copy to the dll project. Oh well, learned a bunch of stuff about MEF, so not completely wasted days :)