title: Inject Adapter to Fragment using Dagger2
body: <p>I have followed Android Architecture Blueprints Dagger2 for dependency injection : <a href="https://github.com/googlesamples/android-architecture/tree/todo-mvp-dagger" rel="nofollow noreferrer">https://github.com/googlesamples/android-architecture/tree/todo-mvp-dagger</a></p>
  
  <p>Now I want to inject Adapter to my Fragment class : </p>
  
  <pre><code>@ActivityScoped
  class MainFragment @Inject
  constructor(): DaggerFragment() {
  
      @Inject lateinit var adapter : ArtistAdapter 
  }
  </code></pre>
  
  <p>And I have following in the module class : </p>
  
  <pre><code>@Module
  abstract class MainModule {
      @FragmentScoped
      @ContributesAndroidInjector
      internal abstract fun mainFragment(): MainFragment
  
      @Module
      companion object {
          @Provides
          @ActivityScoped
          @JvmStatic internal fun provideArtistAdapter() = ArtistAdapter()
      }
  }
  </code></pre>
  
  <p>But for some reason it fails to display data in RecyclerView. When I don't use injection and simply use <code>val adapter = ArtistAdapter()</code>, it works.</p>
  
  <p>What am I missing in injection using Dagger2?</p>
  
  <p>Addenda :</p>
  
  <p><code>mainFragment</code> is implementing a callback as a click listener:</p>
  
  <pre><code>interface ArtistClickCallback {
      fun onClick(artist: LastFmArtist, poster : ImageView)
  }
  </code></pre>
  
  <p>And :</p>
  
  <pre><code>class MainFragment : DaggerFragment(), ArtistClickCallback
  </code></pre>
  
  <p>And here is fragment module :</p>
  
  <pre><code>@Module
  class MainFragmentModule {
  
      @Provides
      fun provideArtistAdapter(mainFragment: MainFragment) = ArtistAdapter(mainFragment)
  
  }
  </code></pre>
  
  <p>But I get following exception when I remove @Inject from Fragment constructor:</p>
  
  <pre><code>error: [Dagger/MissingBinding] com.sample.android.lastfm.ui.main.MainFragment cannot be provided without an @Inject constructor or an @Provides-annotated method. This type supports members injection but cannot be implicitly provided.
  public abstract interface AppComponent extends dagger.android.AndroidInjector&lt;com.sample.android.lastfm.LastFmApp&gt; {
                  ^
    A binding with matching key exists in component: com.sample.android.lastfm.ui.main.MainModule_MainFragment$app_debug.MainFragmentSubcomponent
        com.sample.android.lastfm.ui.main.MainFragment is injected at
            com.sample.android.lastfm.ui.main.MainActivity.mainFragment
        com.sample.android.lastfm.ui.main.MainActivity is injected at
            dagger.android.AndroidInjector.inject(T) [com.sample.android.lastfm.di.AppComponent → com.sample.android.lastfm.di.ActivityBindingModule_MainActivity$app_debug.MainActivitySubcomponent]
  </code></pre>