Derik Whittaker



Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
AutoWire with StructureMap does not wire dependencies which are not public

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,

Posted 03-22-2009 2:34 PM by Derik Whittaker
Filed under: ,



James Brechtel wrote re: AutoWire with StructureMap does not wire dependencies which are not public
on 03-22-2009 5:24 PM

I wish you had posted this 2 weeks ago....could have saved me a couple hours.  Instead I had to learn it the hard way.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)