Not really. The problem here is that when you write a piece of code, for example:
Runnable r = new MyFooRunnable();
you essentially decide that Runnable you will need MyFooRunnable (and not MyBarRunnable or the third). Sometimes you want to defer this decision from compilation time to deployment time, so the installer can decide how the individual application modules are made up of should be glued together.
This has traditionally been done with factories, but it only moves the actual solution around in the code, and you still need to know all the possibilities when coding a factory or let it read the instructions from the configuration file (which is usually fragile for refactoring).
Dependency Injection is a formalization of configured factories in such a way that the code does not need to know anything about how everything works. It also explains why annotations were so useful for indicating where dependency injection should occur. If during code execution in a non-DI installation (for example, the JUnit test), then there is nothing (which would be difficult to do with factories clogged throughout).
Thus, the Injection Dependency, used in a broad sense, allows you to write modules that are “well-bound” to each other without knowing about each other at compile time. This is very similar to the concept of a jar file, but more time has passed for ripening.
source share