title: Guice field injection
body: <p>So here's the thing. I'm trying to inject some fields with guice, but it turns out that they are always null (not trying to use them on the constructor).</p>
  
  <pre><code>public class A {
  
      @Inject
      private SomeClass bar;
  
      public A() {
          foo();
      }
  
      public someMethod() {
          bar.doSth();
      }
  
  }
  
  public class B {
  
      private A a;
  
      public B() {
          a = new A();
      }
  
      public someOtherMethod() {
          a.someMethod();
      }
  
  }
  </code></pre>
  
  <p>Now whenever the app executed someOtherMethod and a tries to run bar.doSth a nice NullPointerException is raised.</p>
  
  <p>So in order to fix this i ended Injecting the field manually inside the constructor:</p>
  
  <pre><code>public A() {
      final Injector injector = Guice.createInjector();
      bar = injector.getInstance(SomeClass.class);
  }
  </code></pre>
  
  <p>But this is ugly, unclear, has a lot of boilerplate and I'm forced to do it on many places which make it tedious.</p>
  
  <p>Is there any other way to archive this? Or an explanation of why the field is not being injected?</p>
  
  <p>Thanks</p>
  
  <p>Note:
      I'm currently unavailable to do the propper injection on the constructor (with bar as a parameter) because of the refactoring it would imply. The project is now under heavy production and thus this kind of refactoring can't be done right now.</p>