Today I was trying to retrofit the source code from Stephen Bohlen’s great SOLID Dimecasts on Dependency Inversion (episode will be released on 3/26/2009) in order to have it use StructureMap (in order to better show the DIP concept in the episode Stephen did not show the use of an IoC container). The first thing I did was to try to wire up StructureMap with AutoWiring in order to make my life easier.
However, when I ran though the code for the first time and called ObjectFactory.WhatDoIHave() nothing showed up in the output window. This had me a bit confused. In order to make sure I was not losing my mind, I hard wired a set of dependencies and recalled ObjectFacotry.WhatDoIHave(). This time it outputted the previously setup dependency. However, whey I tried to run it I received a 207 error (could not find the configured instance – not the exact error message).
It then dawned on me that all the classes inside the code base were either private or internal. Normally this would not be an issue, but since StructureMap (and I believe most other IoC containers) required mapped types to be public, the auto scanning did not pickup anything to register. The solution for this was simple, make the needed classes/interfaces public.
If you find yourself in the same situation make sure you ensure all your needed dependencies are public.
Till next time,
03-22-2009 2:34 PM