Ich habe gerade angefangen, mit dem Managed Extensibility Framework herumzuspielen. Ich habe eine Klasse, die exportiert wird und eine Import-Anweisung:
[Export(typeof(IMapViewModel))]
[ExportMetadata("ID",1)]
public class MapViewModel : ViewModelBase, IMapViewModel
{
}
[ImportMany(typeof(IMapViewModel))]
private IEnumerable<IMapViewModel> maps;
private void InitMapView()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ZoneDetailsViewModel).Assembly));
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this);
foreach (IMapViewModel item in maps)
{
MapView = (MapViewModel)item;
}
}
Das funktioniert sehr gut. Die IEnumerable erhalten die exportierten Klassen. Nein, ich versuche, dies zu ändern, um die Lazy-Liste zu verwenden und die Metadaten enthalten, so dass ich die Klasse herausfiltern kann, die ich brauche (gleiche Export wie zuvor)
[ImportMany(typeof(IMapViewModel))]
private IEnumerable<Lazy<IMapViewModel,IMapMetaData>> maps;
private void InitMapView()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ZoneDetailsViewModel).Assembly));
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this);
foreach (Lazy<IMapViewModel,IMapMetaData> item in maps)
{
MapView = (MapViewModel)item.Value;
}
}
Danach hat die Ienumerable keine Elemente mehr. Ich vermute, dass ich irgendwo einen offensichtlichen und dummen Fehler gemacht habe