Add Parameter to RegisterCatalog to add UNIQUE parts


A suggestion that I believe would be beneficial to a lot of developers, would be to add the ability to register the parts of the Aggregate catalog, ignoring duplicates.
The issue is, that when I register my exported parts, I get duplicate registrations for the same Export - leading me to the exception, "ImportCardinalityMismatchException", when I try to Resolve<T>().
There isn't an easy work around that I have found and I believe it would be nice to have as part of this package.
Code sample below:
    private static void RegisterAssemblies(string assemblyPath, string searchPattern)
        string[] directories = Directory.GetDirectories(assemblyPath, "Debug", SearchOption.AllDirectories);
        var exportedParts = new AggregateCatalog();
        foreach (string directory in directories)
            var assemblyCatalog = new DirectoryCatalog(directory);


montijr2007 wrote Jul 5, 2012 at 6:53 PM

Here is what I believe would work- Add this to the UnityContainerExtensions source code for the "RegisterCatalog" method:

public static void RegisterCatalog(this IUnityContainer unityContainer, ComposablePartCatalog catalog)
  lock (unityContainer)
       var compositionIntegration = EnableCompositionIntegration(unityContainer);

       IEnumerable<ComposablePartCatalog> parts = compositionIntegration.Catalogs.Distinct().ToList();

       foreach (var part in parts)


wrote Feb 14, 2013 at 7:47 PM