Skip to content
0:00 / 0:00

#dependencyinjection#servicelocator#cleancode

The Clean Code Talks - Don't Look For Things!

Google TechTalks

349K subscribers • 62 videos on Hallway

YouTube
  • Recommended by 2 people: 2 on Stack Overflow and its sister sites.
  • Presented by Miško Hevery
  • An opinion. It argues one side of a question engineers disagree on.

Intermediate. Assumes working knowledge.

291K views17 years ago2 recommendations

Software designTools and practiceDesign patternsTesting

Miško Hevery explains why the Service Locator pattern is an anti-pattern and advocates for dependency injection to improve testability.

Google Tech Talks November 6, 2008 ABSTRACT Clean Code Talk Series Topic: Don't Look For Things! Speaker: Misko Hevery

Why it's here

2 people recommend this

What people say. Recommended as a classic explanation of why the Service Locator pattern is bad for testing and design.

user3511397on Stack Overflow • Recommends

On “Is ServiceLocator an anti-pattern?”

From the testing point of view, Service Locator is bad. See Misko Hevery's Google Tech Talk nice explanation with code examples link to this video starting at minute 8:45. I liked his analogy: if you need $25, ask directly for money rather than giving your wallet from where money will be taken. He also compares Service Locator with a haystack that has the needle you need and knows how to retrieve it. Classes using Service Locator are hard to reuse because of it.

mgw854on Software Engineering Stack Exchange • Recommends

On “Ambient dependency injection through static service locator”

I think you are missing the benefit of dependency injection--that anything the class depends on is given to it, rather than assumed. What you're proposing is the service locator anti-pattern. There are a few cases where I might be tempted to use it (identity), but I'd prefer a clean contract for one reason--I never know how someone is going to use my code. I've seen this in my workplace, where someone designs code with ambient references to web concepts (like HttpContext ) deep inside of a call chain instead of injecting it. A year or two later, and the code can't be reused in a console application because of the static dependencies. The same is true in trying to write unit tests. There's…

u/VORGundamin r/dotnet • Mentions

On “Dependency injection”

Check out Google Tech Talks by Miško Hevery on Youtube. link to this video link to this video