Monday, February 28, 2011

Musings on using a module catalog with Prism

anyone using prism is probably familar with the bootstrapper, the documentation defines the bootstrapper as a class responsible for initialization of an application built using Prism and if you dig into the code for it you will see lots of virtual methods that you can override when setting up your application, one of those is the CreateModuleCatalog(). There are several ways to initialize your modules but using an xaml file is incredibly convenient especially if you only want certain parts of your application to load under certain conditions. Where I work we recently decided to employ this feature so that we could load a subset of the application in the warehouse and not have the sales and other modules loading up at run time, on the flip side the warehouse module doesn't load when the sales team loads the application. The great part for the developer is you don't end up with multiple code bases, your core and infrastructure is shared in one application and different people see different parts of the app depending on what is in the ModuleCatalog.xaml file.

With that said I wanted to point out a little snafu I ran into when configuring the catalog and loading it from the xaml file. most of my modules loaded just fine however one of them was not playing nicely - I was pulling my hair out looking at the module properties and examining it with RedGate but it failed to load each time so I started digging through the prism code. I noticed that inside of ModuleInitializer there was a method called CreatModule and it was calling GetType - here is the line of code

Type moduleType = Type.GetType(typeName);

Then it was checking to see if the moduleType var was null and sure enough it was. That gave me the bright idea... Why not call getType on the module itself and stick that in a variable so I could copy and paste? That is exactly what I did. Actually I think I popped a message box but whatever, once I had the exact info from get type I copied an pasted that in to the ModuleCatalog.xaml file and all my problems where gone! What you are really looking for is the
AssemblyQualifiedName. Here is a screen shot.

The information you get from there goes in the ModulesCatalog.xaml - here is a screen cap.

Just to sum it up here is a quick screen of CreateModuleCatalog

No comments:

Post a Comment