Hacker News new | ask | show | jobs
by SideburnsOfDoom 1535 days ago
it is at heart quite simple. But this characteristic doesn't always mean that it has few benefits. Off the top of my head, things that DI enables include:

* swapping out a class for an equivalent becomes an configuration concern.

* whether a type is a singleton or transient becomes a separate concern to that class's implementation, and it can be changed in the app startup config code.

There can be drawbacks too, if done badly, but I don't think that the argument that "this doesn't do very much" is entirely relevant to the pros and cons.

1 comments

While some configurability is desireable, being explicit is even more so.

I wonder why Zope died out? It has everything, it's a completely sound design, and makes all components interchangeable, and it's very pretty when done properly.

It died out because it's verbose and gets hairy quickly in the real world where not everyone is on the same page, so it never ends up being used "properly".

Go for simpler and you have a higher chance of everybody getting the intent on their first reading of code.

It's going to be hard to get people to not do DI "properly" if you simply ask them to pass dependencies in (though I am sure they still could by eg. passing classes vs instances in).