News for hackers. Stuff that matters.
Re:Dependency Injection is dangerous for your career by zby on Thursday February 10, 2011 @02:40AM (#2201181)
Dependency Injection != using a DI container http://loosecouplings.blogspot.com/2011/01/dependency-inject...

DI is about passing all that is needed through parameters instead of creating it or using globals - this is completely independent from the type of arguments passed - you can pass functions or scalars or objects or whatever. Of course all that passed stuff is still needed to be created somewhere - so DI is also about having a factory of objects - it creates a lot of objects - but creation alone should be simple (and indeed frequently it can even be automated by using a DI framework).

You ask: "What problems can be solved with DI that can't be solved by passing a function?" - OK, I never thought about it from that side - but how about the problem of globals? How do you solve it by using function passing? Let's say you have a global database connection - if you modify it and pass that connection (or more frequently objects created from it) as a parameter to all code that needs it - that is DI. How function passing fits here?

There are no comments on this comment yet.