In a nutshell, dependency lookup is when an object finds a way to create/instantiate/lookup its own dependencies (such as a private property).
Dependency injection is when the same object is provided the dependency by some DI framework.
Dependency lookup:
Code:
private String greeting;
public void printGreeting() {
greeting = GreetingManager.getEnglishGreeting();
System.out.println(greeting);
}
Dependency injection:
Imagine that there is a DI framework, such as Spring, which defines the greeting bean and injects it by calling a setGreeting(String greeting) method.
Code:
private String greeting;
public void printGreeting() {
System.out.println(greeting);
}
The big difference is the dependency injected object doesn't worry about how to get a greeting. It leaves that up to the DI framework. The DI framework is then free to swap out different versions of the greeting for different enviroments, or testing, etc.