title: Dagger2 Field Injection not working
body: <p>I am familiar with Spring dependency injection, but Dagger2 is new to me. I am trying to get a simple java application working but field injection does not work.</p>
  
  <p>I have a class <code>Main</code>, that depends on a class <code>MainBusiness</code> which in turn depends on <code>MainDao</code>. </p>
  
  <p><code>MainBusiness</code> gets injected into <code>Main</code> fine, but <code>MainDao</code> does not get injected into <code>MainBusiness</code> and throws a <code>NullPointerException</code>.</p>
  
  <p>Here is the <code>MainDao</code> that implements an <code>interface</code> <code>IMainDao</code></p>
  
  <pre><code>public class MainDao implements IMainDao
  {       
      @Inject
      public MainDao()
      {
      }
  
      public String getResource()
      {
          return "This is the resource you are looking for";
      }
  }
  </code></pre>
  
  <p>Here is the <code>MainBusiness</code> that implements <code>IMainBusiness</code></p>
  
  <pre><code>public class MainBusiness implements IMainBusiness
  {
      // package friendly field.  
      @Inject
      IMainDao mainDao;
  
      @Inject
      public MainBusiness()
      {
      }
  
      public String getResource()
      {       
          return mainDao.getResource(); // throws NPE here.
      }
  
  }
  </code></pre>
  
  <p>Here is the <code>AppModule</code></p>
  
  <pre><code>@Module
  public class AppModule
  {   
      /**
       * Provides a singleton instance of the MainDao 
       * 
       * @return
       */
      @Provides
      @Singleton
      public IMainDao providesMainDao()
      {
          return new MainDao();
      }
  
      /**
       * Provides a singleton instance of the MainBusiness Class
       * 
       * @return
       */
      @Provides
      @Singleton
      public IMainBusiness providesMainBusiness()
      {
          return new MainBusiness();
      }
  }
  </code></pre>
  
  <p>The <code>AppComponent</code></p>
  
  <pre><code>@Singleton
  @Component(modules = {AppModule.class})
  public interface AppComponent
  {
  
      /**
       * @param main
       */
      void inject(Main main); 
  }
  </code></pre>
  
  <p>And the <code>Main</code> class</p>
  
  <pre><code>public class Main
  {   
      @Inject
      IMainBusiness mainBusiness;
  
      public Main()
      {
          AppComponent dac = DaggerAppComponent.builder().build();        
          dac.inject(this);       
      }
  
      public static void main(String args[])
      {
          Main main = new Main();     
          System.out.println(main.mainBusiness.getResource());
      }
  }
  </code></pre>
  
  <p>It throws an NPE on <code>MainBusiness.getResource(MainBusiness.java:14)</code></p>
  
  <p>What am I missing here? Appreciate any help I can get. </p>
  
  <p><strong>P.S This is a plain <code>Java</code> application. It is not an <code>Android</code> application.</strong></p>