What should it be called?

Dependency Injection or Service Locator

They are different. Don’t mix them up.

Picture by Sara Bakhshi on Unsplash

Dependency Injection is now a big word in Software world. However it’s a concept is actually pretty simple. Some one stated Dependency Injection is a 25-dollar term for a 5-cent concept.

It is simply passing one dependency to a target object. Wikipedia defines it as

A technique whereby one object supplies the dependencies of another object.

With that definition, every one just name the way one get dependency as Dependency Injection. This is not right. I was equally confused as well 😓

There are 3 ways of accessing dependencies for an object

  1. Dependency Injection
  2. Service Locator
  3. Self access or creation. (i.e. instantiate dependencies oneself. Arguably, some doesn’t consider this as dependencies, but this is not the focus of discussion here)

Even Google did state that for it’s Manage dependencies between components

--

--