Ok, so I just posted less than an hour ago, but now I've found something worth talking about. :)
After working my way through Phil Haack's blog on TDD with DI using StructureMap, I found a few things that I thought may be helpful.
Firstly, don't try to use a LINQ to SQL data context as your concrete implementation of an interface. Apparently that doesn't work. :) I tried this and received a StructureMapException:
StructureMap Exception Code: 155 - An exception occurred while trying to create an InstanceFactory for PluginType MvcApplication.Models.IPostRepository,MvcApplication
The inner exception was:
StructureMap Exception Code: 200 - Could not find an InstanceMemento for the requested InstanceKey "LINQToSQL" of of PluginFamily MvcApplication.Models.IPostRepositor
Nasty... As soon as I swapped in a concrete implementation called PostRepository that simply called the methods I had created on top of the data context, everything worked.
Secondly, following the code for the StructureMapControllerFactory object will lead to a compile error because you need to specify a return type from the ObjectFactory.GetNamedInstance method. I used the generic version because I'm too lazy cast now days. That makes the code inside the try block:
Lastly, if you want to use code instead of a configuration file for the StructureMap configuration, add the following to your Global.asax Application_Start event handler:
StructureMapConfiguration.UseDefaultStructureMapConfigFile = false;
So now I have a functional website that uses DI and is unit testable. Hope this helps someone else out there...