Dependency Injection
Factory Pattern
DI is only aware of the dependencies. It does not know anything about the container or factory. It adds coupling between objects, factory, and dependency. It requires both a dependent object and a factory object to work properly.
DI makes the unit tests easier. It does not require boilerplate code. The factory pattern requires the object you want to test, the factory object, and the dependent object.
DI is more flexible than factory patterns. It also gives the facility to switch different DI frameworks such as Spring IOC and Google Guice. It is not much flexible as Dependency Injection.
DI requires a container and configuration in order to inject dependencies. The factory pattern does not require these configuration steps.
Due to less coupling, the result of DI is much cleaner. The client class looks like the POJO class. In the case of the Factory pattern, the client class is not clean as in DI.