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
Reseting Defaults in StructureMap when Injecting Stubs

This is just a short FYI post because this caused me some headache recently.

One thing to keep in mind when you are using StrucutreMap and are Injecting Stubs into the ObjectFactory, you will want to reset the ObjectFactory engine after you done with your tests.

To do this you will need to add this line of code.

How you implement this and where you put it is up to you.  I simply put this as the last line of code in my tests, but you could put it in [TestFixtureTearDown] or if you wanted you could wrap your entire test in a try-finally block and put it there (I did not do this, did not think it was needed).

BTW, the error message you will receive if you have stubs lingering around in your ObjectFactory is the following ‘This action is invalid when the mock object is in verified state’.

Till next time

Posted 07-26-2007 7:05 AM by Derik Whittaker
Filed under: ,


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)