开发者

How-To Prevent Module Duplicates with MEF?

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);
    
        conta开发者_如何转开发iner.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜