title: Bidirectional dependency with Dagger 2
body: <p>I'm experimenting with VIPER architecture in my Android app. I use Dagger 2.11 for DI.</p>
  
  <p>Dependencies I have for each VIPER module are:</p>
  
  <ol>
  <li><code>Presenter</code> and <code>Fragment</code> are linked via <code>ViewInput</code> and <code>ViewOutput</code> interfaces.</li>
  <li><code>Presenter</code> and <code>Interactor</code> are linked via <code>InteractorInput</code> and <code>InteractorOutput</code> interfaces.</li>
  <li>Some other dependencies, we are not interested in.</li>
  </ol>
  
  <p>This is how my Dagger Module looks like:</p>
  
  <pre><code>Module(includes = [Module.Declarations::class])
  class Module(private val viewInput: ViewInput) {
  
      @Module
      interface Declarations {
  
          @Binds
          @FragmentLevel
          fun bindViewOutput(viewOutput: Presenter): ViewOutput
  
          @Binds
          @FragmentLevel
          fun bindInteractorOutput(interactorOutput: Presenter): InteractorOutput
  
          @Binds
          @FragmentLevel
          fun bindInteractorInput(interactorInput: Interactor): InteractorInput
      }
  
      @Provides
      @FragmentLevel
      fun provideViewInput() = viewInput
  }
  </code></pre>
  
  <p>Now when I call <code>inject</code> in my <code>Fragment</code> the following happens:</p>
  
  <ol>
  <li><code>Presenter</code> is injected into <code>Fragment</code> via <code>ViewOutput</code> interface</li>
  <li><code>Interactor</code> is injected into <code>Presenter</code> via <code>InteractorInput</code> interface</li>
  <li><code>Presenter</code> is <strong>not</strong> injected into <code>Interactor</code>, because of <code>Lazy</code> type (to prevent cyclic dependencies).</li>
  <li>After the first call of <code>Lazy.get()</code> <code>Presenter</code> is injected into <code>Interactor</code> via <code>InteractorOutput</code> interface.</li>
  </ol>
  
  <p>The problem is that in the 1st and 4th steps <strong>different</strong> instances of <code>Presenter</code> are injected. How can I make dagger inject the same presenter into <code>Fragment</code> and <code>Interactor</code>?</p>
  
  <p>Or maybe I need to fix the dependency cycle in the other way?</p>