title: Service Locator vs. Dependency Injection
body: <p>I'm reviewing code with a lot of statements like this:</p>
  
  <pre><code>private SomeInterface x = Locator.getInstance(SomeInterface.class)
  </code></pre>
  
  <p>I would expect something like</p>
  
  <pre><code>private SomeInterface x;
  
  @Inject
  public Consumer(SomeInterface x){ // constructor
      this.x = x;
  }
  </code></pre>
  
  <p>Is there something wrong with the first approach? Ok, dependencies are not so obvious, but implementations could easily be swapped through configuration of Locator.</p>