The DI discussion continues…
Posted by Davy Brion on August 22nd, 2007
Round 3:
Jacob and Ayende continue to discuss DI on their blogs.
It seems that Jacob thinks that DI brings a lot of development overhead with it, which i couldn’t disagree with more. That is, if you don’t go overboard with the DI usage. I use DI where it makes sense to me, not because it’s fashionable or because it’s what the cool developers tell me to use. I mostly use it in places where it takes away from the development overhead, in the form of easy testability and perhaps even more important: fast tests. Nobody likes to run slow tests so getting them as fast as you can, while still correctly covering the functionality that you want to test should be one of your goals if you’re doing TDD.
So where does that leave DI? Well, i mostly use it when i want to test code that is dependent on components that can either be slow, or have erratic/unpredictable behaviour. And sometimes i’ll use it just because it makes something a lot easier to test. I certainly don’t use DI for each and every dependency in my code. This approach certainly doesn’t bring a lot of development overhead with it since it’s rather easy to do. Initially while coding, it might cost you a few more minutes. But that’s really not a lot is it? The time i save while being able to run my entire test suite in a matter of seconds whenever i make a change or add a new feature more than makes up for those few minutes i lost initially.

August 24th, 2007 at 6:00 am
DI indeed seems like overhead and clumsy when coding simple, straightforward applications like webapplications. On the other hand, I once coded a communication server to handle connections to different kinds of mobile devices (together with routing and connections to a variety of different services). I must say, setting this up without DI would have been hell! Once you’re used to having an Ioc, you’re hooked and as a benefit it gives you some extra cool features like aop, testability,..