tags:

views:

71

answers:

1

Hi,

How can i prevent from MEF to load duplicates Modules in the case of the presence of 2 copies of the same Assembly (maybe by mistake)

  • Assembly1.dll

  • Assembly2.dll (copy of Assembly1)

    [ImportMany]
    public IList<IModule> Modules { get; private set; }
    
    
    public void BuildUp()
    {
        Modules = new List<IModule>();
    
    
    
    var catalog = new DirectoryCatalog(@".\Modules");
    var container = new CompositionContainer(catalog);
    
    
    container.ComposeParts(this);
    
    }
+1  A: 

Instead of using a DirectoryCatalog, use an AggregateCatalog. You will have to write code that looks at all the Assemblies in the modules directory, figures out if the current one is a duplicate of one it has already processed, and if not, creates an AssemblyCatalog for that Assembly and adds it to the AggregateCatalog.

I'm not sure exactly what logic you would be able to use to detect that two DLLs with different names are the "same" assembly, though.

Daniel Plaisted
I need to prevent duplicates types implementations of IModule being loaded by MEF. Thanks i'll try in this way.
Yoann. B