Reputation: 4442
When will you use dependency injection? Is there any overwhelming benefit of using dependency injection?
Upvotes: 5
Views: 1708
Reputation: 80194
Fowler has good comparision between the two in his Inversion of Control Containers and the Dependency Injection pattern Heading. In his concluding thoughts, he says
Dependency Injection is a useful alternative to Service Locator. When building application classes the two are roughly equivalent, but I think Service Locator has a slight edge due to its more straightforward behavior. However if you are building classes to be used in multiple applications then Dependency Injection is a better choice.
You can find more view points and comparisons in here
For DI:
Against DI:
Upvotes: 5