views:

166

answers:

5

What are some of the things to watch for (pitfalls) while using IOC container?

A: 

If you use spring aop, there's a lot of magic going on and if something doesn't work right it's really hard to figure out what's wrong.

toby
A: 

Disposing the right things at the right times, otherwise you will create memory leaks.

Gerrie Schenck
A: 

Complexity of configuration.

Keep an eye out up-front that the complexity you're getting with the various XML files and setup is worth the problem you're addressing. One example - in Apache HiveMind, the configuration of binding class instances to each other, and passing configuration information in can easily become more difficult to maintain, read, and understand then the equivalent Java would have required.

jbm
Every major modern container offers some kind of fluent interface configuration... XML config is being generally deprecated
Mauricio Scheffer
+1  A: 

Trying not to fall too much for a Service Locator pattern, where some static wrapper to your IoC container provides you with instances of type xyz. While you may need it at times, ensuring that you do inject your dependencies to your consuming type will keep your code a lot cleaner and make the container much less intrusive.

flq
A: 

Troubleshooting can be harder in my experience. Not only are you working against interfaces, which means it can be difficult to identify the actual type of the instances used by looking at the code. You also move a lot of the wiring from compile time to runtime (which is one of the point of IoC of course, but it doesn't do wonders for finding problems).

Brian Rasmussen
Agreed. I'm not a huge fan of IOC containers for this reason. It's one of the drawbacks that people tend to gloss over. :)
jalf