Dependency injection: so simple...

The best explanation of dependency injection I've seen so far.

It's so simple...

As Elliotte Rusty Harold recommends, James Shore's entry about Dependency Injection is worth reading.

As he says: "Dependency Injection means giving an object its instance variables. Really. That's it."

... or not that simple?

Well, it looks indeed simple. But, who is injecting those dependencies for you? A framework, you say?

Yep. A framework. A framework that hides software complexity by moving those "dependencies" under the carpet.

In the form of XML configuration files, for instance.

So beware of those frameworks. Be careful out there. You may end up hating frameworks, as Joel says.

And let me explain myself. I don't hate frameworks. I just hate using "general-purpose tool-building factory factory factory" where a hammer does the job.

After all, dependency injection is just assigning a value to a variable, right? ;-)

I wish you a Merry Christmas,

Antonio

blog comments powered by Disqus