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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With