Michael Spitsin
1 min readDec 6, 2018

--

Hi. First of all thank you for great job and interesting article.

One thing, that bothered me whole morning is your definition of DI and the second example of not DI way:

Second: Get dependencies inside the constructor

In this example you provide class C, and class B though appropriate constructors.
Then you giving definition of DI:

Dependency injection is a way that we delegate handling dependencies to the third party so no other part of our code should be worried about providing dependencies.

Correct me, if I’m wrong, but you second example is a canonical example of DI through the constructor. What you describing next is just a way to organize your dependencies containers/factories/providers, thus the way to build framework based on DI approach.

And your definition is right: you (a class, an entity) just give responsibility to provide needed dependencies outside. That’s all. It is doesn’t matter, who will provides it. So your second example is DI through the constructor. And your next part of article is about building environment around DI principle.

You can see wiki: https://en.wikipedia.org/wiki/Dependency_injection
You can check this article: https://medium.freecodecamp.org/a-quick-intro-to-dependency-injection-what-it-is-and-when-to-use-it-7578c84fa88f
Also here is Fowler’s article: https://www.martinfowler.com/articles/injection.html

Don’t understand me wrong. Your intention is good. And I understood from the title of article, that you want to provide a basic knowledge to people, who do not know about DI or just barely faced with this principle, but this provided knowledge is not precise and, thus, correct enough.

--

--

Michael Spitsin
Michael Spitsin

Written by Michael Spitsin

Love being creative to solve some problems with an simple and elegant ways

Responses (1)