The DI discussion continues…
Posted by Davy Brion on 22nd August 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.
Posted in Dependency Injection, Software Development, Test Driven Development | 1 Comment »