Hail a CAB
Microsoft's Patterns and Practices group created an application block called the Composite UI Application Block (”CAB”) and I have been trying to implement it on my project at Urban Science. The application block is a class library that allows developers to architect user interfaces the correct way. It is currently geared towards smart client application development but I believe their intent is to use this for both windows and web clients in the future. They have broken up the assemblies so that all the architecture classes are in the base assembly and then they also have a windows forms assembly that implements some windows forms specific items and such off of the base assembly.
The assemby is great because it breaks out each piece of you entire application into “work items”. Each work item is suppose to represent a use case within your application. Each work item can then have multiple user interfaces (views) and controllers for the user interfaces. Each of these can be compiled into their own “module“ assembly. The shell application can just be a blank windows forms (there are other shell types such as console shell type and you can extend it as well) that defines “workspaces”. The shell loads the specific workspaces with modules based on a configuration file. Moving your interface around or swapping out modules is just a change within a configuration file! Other super duper highlights include:
- Publish/Subscribe events between interfaces without them even knowing about each other
- Handle the same command in different interfaces and dlls without them knowing about each other
- Keep state within controllers with a simple attribute
Here is a architecture diagram of two of the assemblies talked about above:
They have several quick starts to get you started. The problem I have with the quick starts are that they all have the views (user controls) compiled in the same assembly as the rest of the stuff (work items and controllers) in the module. This should really be broken out so that the views are in their own assembly. That way it is easy to swap out views if you want a different view to perform the same function. We have that requirement at Urban Science. To get around this issue, I wrote a view loader service that reads a configuration file in order to get the view to load. You can expand this service to load a different view based on some criteria such as user name or role or something else.
You should give this application block a look if you are implementing complicated UI stuff in a windows client application. You can go download the C# source code here and the VB source code here. They have just dropped a December release. You should plan on taking at least a half a day to get familiar with the CAB object model. More information about the CAB is available on a gotdotnetworkspace here. I also found this webcast to be very helpful. I will continue to blog about this as I develop more in it and more for it.
