title: Constructor dependency injection with Dagger2 Android
body: <p>I want to inject MyRepositiry class to my MyPresenter. The only thing that I don't quite understand if <code>@Inject PostRepository mRepository;</code> would be enough in this case or I need to do this:</p>
  
  <pre><code> public AddPostPresenter(PostRepository postRepository, AddPostContract.View view) {
      this.mRepository = postRepository;
      mView = view;
  
      mFireBaseApp.getApplicationComponent().inject(this);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Module public class DataModule {
  
      FireBaseApp mFirebaseApp;
  
      public DataModule(FireBaseApp fireBaseApp) {
          this.mFirebaseApp = fireBaseApp;
      }
  
      @Provides
      @Singleton
      FirebaseAuth getFirebaseAuth() {
          return FirebaseAuth.getInstance();
      }
  
      @Provides
      @Singleton
      FirebaseUser getCurrentUser(FirebaseAuth firebaseAuth) {
          return firebaseAuth.getCurrentUser();
      }
  </code></pre>
  
  <p>My Component:</p>
  
  <pre><code>@Singleton @Component(modules = DataModule.class)
      public interface ApplicationComponent {
      void inject(MainActivity mainActivity);
      void inject(PostRepository postRepository);
      void inject(AddPostPresenter addPostPresenter);
      void inject(AddPostActivity addPostActivity);
  }
  </code></pre>
  
  <p>Application class:</p>
  
  <pre><code>    public class FireBaseApp extends Application {
  
      private ApplicationComponent component;
  
      @Override
      public void onCreate() {
          super.onCreate();
  
          if (BuildConfig.DEBUG) {
              Timber.plant(new Timber.DebugTree());
          }
  
          inject();
  
      }
  
      private void inject() {
          component = DaggerApplicationComponent
                  .builder()
                  .dataModule(new DataModule(this))
                  .build();
      }
  
      public ApplicationComponent getApplicationComponent(){
          return component;
      }
  }
  </code></pre>
  
  <p>Repository:</p>
  
  <pre><code>public class PostRepository implements IPosts {
  
  FireBaseApp fireBaseApp;
  DatabaseReference mDatabaseReference;
  FirebaseAuth mFirebaseAuth;
  FirebaseUser mFirebaseUser;
  
  @Inject public PostRepository() {
      mFirebaseAuth = FirebaseAuth.getInstance();
      mFirebaseUser = mFirebaseAuth.getCurrentUser();
      mDatabaseReference = FirebaseDatabase.getInstance().getReference();
  }
  </code></pre>
  
  <p>And finally Presenter:</p>
  
  <pre><code>public class AddPostPresenter implements AddPostContract.UserActionListener {
  
  @Inject PostRepository mRepository;
  FireBaseApp mFireBaseApp;
  
  private final AddPostContract.View mView;
  
  
  public AddPostPresenter(PostRepository postRepository, AddPostContract.View view) {
      this.mRepository = postRepository;
      mView = view;
  
      mFireBaseApp.getApplicationComponent().inject(this);
  }
  </code></pre>
  
  <p>So again my question is do I need to do this in MyPresenter constructor <code>mFireBaseApp.getApplicationComponent().inject(this);</code><br>
  or having PostRepostory with @Inject would be enough? <code>@Inject PostRepository mRepository;</code></p>