Is the word “Dependency” used correctly in DI?

The word “Dependency” is used a lot in programming. But I think we might be using it wrong in many ways. I will use “Dependency Injection” in this post as an example. According to the, the “Dependency” means:

  1. the state of being dependent; dependence.
  2. something dependent or subordinate; appurtenance.
  3. an outbuilding or annex.
  4. a subject territory that is not an integral part of the ruling country.

Let’s take the second meaning. Dependency denotes a thing that depends on another thing(s). However, when we say “Dependency Injection”, what the dependencies are not the objects requesting other objects to be injected to themselves, but the objects that are being injected. But according to the meaning given in the dictionary, this understanding is wrong. Actually, we are not injecting dependencies, but dependencies request other objects to be injected since they depend on those objects that they specify in their constructors. Perhaps a name like “Requestor Dependency” pattern would be accurate.

A justification would be that we call the injected objects “Dependencies” because they are part of a dependency graph in which they depend on the other objects, but from the more realistic stand point, this justification of the way how the word “dependency” is used in DI pattern seems not sufficient to me.

I am not a native English speaker. Therefore, I may be wrong on this subject. But whenever I think about dependency, the meaning of it in the dictionary and how it is used in the programming conflict with each other.


Dependency Injection uses the term “dependency” correctly.

A dependency is simply a setting, value, or configuration on which a program depends. Looking up dependent is much more instructive. There one finds (slightly paraphrasing and abridging, and amongst other meanings):

  1. relying on someone or something else
  2. conditioned or determined by something else; contingent
  3. subordinate; subject
  4. not used in isolation; used only in connection with other forms
  5. having values determined by one or more independent variables

Those all fit “dependency injection” quite nicely.

In DI, the values and configurations a program depends on are externally provided (“injected”). In practice, the application server, program loader, test harness, or other “middleware” responsible for injection provides not just simple values (e.g. “the file to process is xyz.jpg” or “the program should use 6 worker threads for this run”), but also the names or addresses of services (e.g. databases, parsers, libraries) the program should use, and the credentials and configurations with which to use those services. Whether simple values or definitions of complex services and objects, the information injected invariably specifies things on which the target program depends, and that the developer has judged appropriate to be externally defined rather than hard-wired into program source code.

It is true that the “dependency” of DI does not comport with every possible meaning of “dependency.” Its “annex” and “subordinate territory” meanings, for example, are absent. But that’s par for the course in using natural languages in technical settings. Nor does a phrase like “operating system” align with every possible meaning or sense (denotation or connotation) of “operating.”

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *