I am building a mvc app using structuremap.. I have quite a few places where I use ObjectFactory.GetInstance(). my app was working fine until I added a couple more functions, now all it does when I start up my app in VWD2010 express is stall and give me a StackOverflowException when I debug. and most of the exceptions are with ObjectFactory.GetInstance calls.. How do I fix this? Thanks!
Well I get it in a few different instances of ObjectFactory.GetInstance() when I first start debugging.. So Im not sure what exactly I should post..
I've never run into this problem, but it does sound like it could be a circular dependency issue. To figure out exactly what's going on, you could start by putting breakpoints in every constructor of the classes you're trying to build up and see what might be getting called multiple times.
As a side note, if you're using GetInstance() in quite a few places then you're not using it as intended. You should be calling GetInstance() in only a few key high-level infrastructure locations (e.g. A bootstrapper, controller factory, etc.).
First I would try to reduce the number of times you need to call GetInstance. Try to do Contructor Injection as much as possible.
Look into how you can get your MVC Controllers from the container. Since this is your point of entry into your application, if you have those in your container and all dependencies in the container, you should be able to use Contructor Injection almost completely.