Search code examples
c#wpfunity-containerprism

Prism 7 - Merge ConfigurationModuleCatalog with DirectoryModuleCatalog


I would like to use both:

protected override IModuleCatalog CreateModuleCatalog()
{
    return new ConfigurationModuleCatalog();
}

and

protected override IModuleCatalog CreateModuleCatalog()
{
    return new DirectoryModuleCatalog() { ModulePath = @".\Modules" };
}

I found this question:

Prism 6 - Merge ConfigurationModuleCatalog with DirectoryModuleCatalog

But the link in the answer is dead, it returns 404.

I also searched for the "AggregateCatalog" that was mentioned in the answer - I looked here:

https://github.com/PrismLibrary/Prism/tree/master/Source/Prism/Modularity

and here:

https://github.com/PrismLibrary/Prism/tree/master/Source/Wpf/Prism.Wpf/Modularity

but I didn't find it...

Is there any way to do this in Prism 7 with Unity?


Solution

  • Try this:

    protected override IModuleCatalog CreateModuleCatalog()
    {
        var a = new DirectoryModuleCatalog() { ModulePath = @".\Modules" };
        var b = new ConfigurationModuleCatalog();
    
        return new ModuleCatalog(a.Modules.OfType<ModuleInfo>().Concat(b.Modules).OfType<ModuleInfo>());
    }