
Understanding SOLID Principles: Dependency Inversion - rbanffy
https://dev.to/theodesp/understanding-solid-principles-dependency-injection
======
Ace17
"The drawback of dependency Inversion is that you need a dependency injection
container, and you need to configure it."

This is simply wrong.

You can do dependency _injection_ without a container (using factories, or
link-time polymorphism).

Dependency _inversion_ is a lot more general:

Depending on a header file (interface) instead of a specific implementation
already is a kind of dependency _inversion_.

Having a language-independent IR in a compiler also counts as dependency
_inversion_ (compared to an implementation where the frontend calls the
backend): it prevents dependencies between the frontend and the backend (whose
reasons to change generally aren't correlated), by making everybody depend on
the IR instead.

~~~
rmaus
Not only is it wrong, but it's wildly misleading about why dependency
inversion is desirable. This article is trash; it's basically a copy/paste of
the Wikipedia entry on dependency inversion, rewritten awkwardly (not to
mention the usage of Comic Sans).

------
trevor-e
My problem with blog posts on SOLID (like this one) is they overcomplicate
ideas that should be simple. This entire article could be replaced with:

\- When trying to make code testable, it's easier to configure from the
outside than inside.

There's no need to mention other topics like factories, DI containers, etc.
All of those are obvious abstractions on top of the very simple idea.

~~~
marcosdumay
They are only obvious after you see them.

My only criticism is about articles that confuse the principle with the means
you use to obtain it. Yes, do talk about factories and containers, but
separate them from the principle and keep in mind that there are many other
ways to get it. You don't _need_ a DI container.

Besides, it only provides you an specific kind of testability, that may or may
not be the best way to test your code.

------
danbruc
Dependency Inversion ≠ Dependency Injection

------
u801e
There's also "Dependency Rejection" [http://blog.ploeh.dk/2017/01/27/from-
dependency-injection-to...](http://blog.ploeh.dk/2017/01/27/from-dependency-
injection-to-dependency-rejection/)

