I'm loading a set of modules using a DirectoryModuleCatalog in Prism for wpf. I want to load a module and display its default view on a button click in my shell application (all the modules are labelled with [Module(OnDemand = true)]
attribute). I cache the module names when they are discovered:
var modulesCatalog = new DirectoryModuleCatalog {ModulePath = @"C:\WhereTheModulesLive"};
modulesCatalog.Initialize();
foreach (var module in modulesCatalog.Modules)
{
_availableModules.Add(module.ModuleName);
}
This enables me to map the name of the module I require to a button (the below is called as a result of a command, triggered by a button click, where the buttons are populated from _availableModules). At the moment I navigate to the default view by naming it by convention:
private void LoadAndDisplayModule(string moduleName)
{
_moduleManager.LoadModule(_availableModules.GetNameOfModuleToLoad());
_moduleManager.Run();
_regionManager.RequestNavigate(RegionNames.ContentRegion, moduleName + "View");
}
This feels like an untidy and brittle implementation - and there's some more information which I'd ideally like to embed in the module - ideally to be accessed before it's loaded. I wonder if there's a way of doing this? I wondered about adding a custom attribute to the module, but I can't work out how I would read it during module discovery (without rewriting the DirectoryModuleCatalog). Alternatively, if there were a way to make a module support an interface, which it could be cast to (MyModule : IModule, ISupportsDefaultView
), but I think that directly accessing IModule objects goes against the Prism design philosophy. Any ideas?