MEFedMVVMCatalog.CreateCatalog(catalog) Removing IMediator

Sep 23, 2011 at 6:57 PM

I'm having a problem with the call to MEFedMVVMCatalog.CreateCatalog(catalog).

I have implemented my own ComposablePartCatalog where I load the catalog with only the assemblies that I need:

private AggregateCatalog GetCatalog()
    {
      var rootAssembly = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
                      where assembly.FullName.Contains("MEFedMVVM")
                      select assembly).First();


      var location = Path.GetDirectoryName(rootAssembly.Location);

      var catalog = new AggregateCatalog();

      foreach (var assembly in Directory.GetFiles(location, "*.dll", SearchOption.TopDirectoryOnly))
      {
        var assm = Assembly.LoadFrom(assembly);
        var referencesAssemblies = assm.GetReferencedAssemblies();
        if (referencesAssemblies.Length > 0 && referencesAssemblies.Where(x => x.FullName.Contains("MEFedMVVM")).FirstOrDefault() != null)
        {
          catalog.Catalogs.Add(new AssemblyCatalog(assembly));
        }
      }
      
      catalog.Catalogs.Add(new AssemblyCatalog(rootAssembly));

      return catalog;
    }

 When this returns the next important line looks like this: 

 var catalog = composer.InitializeContainer();
 var mefedProvider = new MEFedMVVMExportProvider(MEFedMVVMCatalog.CreateCatalog(catalog));

Before this call I can see that my catalog has 13 parts, after this call my catalog has only 8 parts.  The creation of the MEFedMVVMCatalog removed all the parts found within the MEFedMVVM.dll, namely the IMediator that is being referenced in my other exports.

I look at the code: 

public MEFedMVVMCatalog(ComposablePartCatalog inner, bool designTime)
        {
            _inner = inner;
            _partsQuery = designTime ?
                _inner.Parts.Where(p => p.ExportDefinitions.Any(ed => 
                    !ed.Metadata.ContainsKey(ExportService.IsDesignTimeServiceProperty) || 
                    ed.Metadata.ContainsKey(ExportService.IsDesignTimeServiceProperty) 
                    && 
                    (ed.Metadata[ExportService.IsDesignTimeServiceProperty].Equals(ServiceType.DesignTime) || 
                    ed.Metadata[ExportService.IsDesignTimeServiceProperty].Equals(ServiceType.Both))
                    ))
                : _inner.Parts.Where(p => p.ExportDefinitions.Any(ed => !ed.Metadata.ContainsKey(ExportService.IsDesignTimeServiceProperty) || 
                    ed.Metadata.ContainsKey(ExportService.IsDesignTimeServiceProperty) 
                    && 
                    (ed.Metadata[ExportService.IsDesignTimeServiceProperty].Equals(ServiceType.Runtime) || 
                    ed.Metadata[ExportService.IsDesignTimeServiceProperty].Equals(ServiceType.Both))));
        }

I can see that they are being filtered out as either designTime exports or something?

Can anyone explain what i'm doing wrong?