I'm writing an IntelliSense implementation and I'm trying to get access to VisualStudio's icon set. I understand you're meant to use MEF and somehow the property/field you import should be automatically populated. Currently I have:
[Import]
public IGlyphService GlyphService { get; set; }
GlyphService is always null. What am I missing?
Apparently you do indeed have to manually populate and compose a CompositionContainer. My solution looks something like this:
// An aggregate catalog that combines multiple catalogs
var catalog = new AggregateCatalog();
// Adds all the parts found in the necessary assemblies
catalog.Catalogs.Add(new AssemblyCatalog(typeof(IGlyphService).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(SmartTagSurface).Assembly));
// Create the CompositionContainer with the parts in the catalog
CompositionContainer mefContainer = new CompositionContainer(catalog);
// Fill the imports of this object
mefContainer.ComposeParts(this);
After running this the current object (or the one you have selected in compose parts) will have it's Imports populated. I ran into a couple of issues with this, including needing to have the referenced dll's in the program's bin folder.