I’m using Prism V2 with a DirectoryModuleCatalog and I need the modules to be initialized in a certain order. The desired order is specified with an attribute on each IModule implementation.
This is so that as each module is initialized, they add their View into a TabControl region and the order of the tabs needs to be deterministic and controlled by the module author.
The order does not imply a dependency, but rather just an order that they should be initialized in. In other words: modules A, B, and C may have priorities of 1, 2, and 3 respectively. B does not have a dependency on A – it just needs to get loaded into the TabControl region after A. So that we have a deterministic and controllable order of the tabs. Also, B might not exist at runtime; so they would load as A, C because the priority should determine the order (1, 3). If i used the ModuleDependency, then module “C” will not be able to load w/o all of it’s dependencies.
I can manage the logic of how to sort the modules, but i can’t figure out where to put said logic.
I didn’t like the idea of using ModuleDependency because this would mean that module a would not load when module b was not present, when in fact there was no dependency. Instead I created a priority attribute to decorate the module:
I then decorated the modules like this:
I created a new descendent of DirectoryModuleCatalog:
Finally, I changed the bootstrapper to use this new catalog:
I’m not sure if the stuff with assembly loading is the best way to do things, but it seems to work…