What are some of the things to watch for (pitfalls) while using IOC container?
views:
166answers:
5If 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.
Disposing the right things at the right times, otherwise you will create memory leaks.
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.
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.
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).