For a large, enterprise application at work, I have been utilizing the Prism (CompositeWPF) framework. The application is still in progress, so I am unable to discuss it’s nature too much in detail. However, Prism has been a large help in getting the base framework for the application laid out and constructed. After finishing a few other tasks, I decided to check the status of the CompositeWPF project and look for any updates. That day just happened to coincide with Prism2′s latest release. The update sounded appealing, so I started the process of moving everything over to it.
While moving over to the February 2009 release of Prism2, I ran into issues with a few of the pieces I was using from the CompositeWPFContrib project. For example, the Windsor container bootstrapper had not been updated for the new release of Prism, leading to many problems. In order to fully move over to Prism2, I’d need to either give up on using Windsor, or create a new bootstrapper for Prism2 capable of working with Castle Windsor. Choosing option 2, I started with the bootstrapper for Unity and with the base Castle Windsor implementation for ServiceLocator, then modified them quite a bit. The final results that I ended up with will be posted below.
One significant difference between Castle Windsor and Unity came to light while writing and testing these new classes. If a specific instance of a class that hasn’t been registered into the container is requested from Unity, Unity doesn’t complain and just goes ahead and injects what is needed. Castle Windsor, on the other hand, will throw an exception complaining that the component wasn’t registered. Both seem like valid approaches, but I wanted to make the transition as simple as possible. So, to avoid changing too much of the logic found within Prism2 (and the bootstrapper), I added a “ResolveEx” extension function to IWindsorContainer. If a specific class is requested through this function that isn’t in the container, it will register it as transient and return an instance. I also changed the ServiceLocator implementation for Castle Windsor to use “ResolveEx” if a key is not passed in.
Read the rest of this entry »