Todd Fast's Blog

Thursday, Nov 18, 2004

Dependency injection vs. service locator

This article by Martin Fowler describes the dependency injection and service locator patterns and offers some pros and cons of each.

As interesting and useful as dependency injection and inversion of control (IoC) containers are, I tend to agree with Martin's conclusion that the service locator is a somewhat more straightforward pattern, especially if a standard locator mechanism like JNDI is available. On the flip side, as developers become more and more accustomed to dependency injection, particularly as a primary idiom for application development, it does offer some interesting opportunities to (at least seemingly) reduce application complexity.

Archives

Tags

Feeds

Search

Links

Navigation

Referers