Introduction I have been evangelizing the use of IoC for a number of years. Frequently the newly converted ask the following two questions:
Which container to use? Which is fastest? My answer to the first is almost always the one you choose, and for the second question I refer them to Martin From’s IoCBattleweb page. I wont get into the reason for my answer to the first question in this post (I will save that for another day).
In my recent post, IoC Challenge – Multiple interfaces to the same singleton instance, I posted an IoC challenge to the community. I also mentioned that on the Ninject discussion groups, a suggestion was posted on how to solve this using Ninject.
Today, I decided to try out that suggestion, and I have to admit, it is quite elegant so far. Here is the source code used.
First, the interfaces.
I have an IoC challenge that I am currently trying to work through. I have a series of classes that implement more than one interface, with the lifetime of the class needing to be a singleton, and I really don’t like the idea of falling back on custom instantiation code along with potentially custom lifetime management code to make this work.
Sound confusing? Here is the model I am trying for.