title: Inject ViewModel using Dagger 2 + Kotlin + ViewModel
body: <pre><code>class SlideshowViewModel : ViewModel() {
  
  @Inject lateinit var mediaItemRepository : MediaItemRepository
  
  fun init() {
      What goes here?
  }
  </code></pre>
  
  <p>So I'm trying to learn Dagger2 so I can make my apps more testable.  Problem is, I've already integrated Kotlin and am working on the Android Architectural components.   I understand that constructor injection is preferable but this isn't possible with <code>ViewModel</code>.  Instead, I can use <code>lateinit</code> in order to inject but I'm at a loss to figure out how to inject.</p>
  
  <p>Do I need to create a <code>Component</code> for <code>SlideshowViewModel</code>, then inject it?  Or do I use the <code>Application</code> component?</p>
  
  <p>gradle:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  apply plugin: 'kotlin-android'
  
  kapt { 
      generateStubs = true
  }
  dependencies {
      compile "com.google.dagger:dagger:2.8"
      annotationProcessor "com.google.dagger:dagger-compiler:2.8"
      provided 'javax.annotation:jsr250-api:1.0'
      compile 'javax.inject:javax.inject:1'
  }
  </code></pre>
  
  <p>Application Component</p>
  
  <pre><code>@ApplicationScope
  @Component (modules = PersistenceModule.class)
  public interface ApplicationComponent {
  
      void injectBaseApplication(BaseApplication baseApplication);
  }
  </code></pre>
  
  <p>BaseApplication</p>
  
  <pre><code>    private static ApplicationComponent component;
  
      @Override
      public void onCreate() {
          super.onCreate();
  
          component = DaggerApplicationComponent
                  .builder()
                  .contextModule(new ContextModule(this))
                  .build();
          component.injectBaseApplication(this);
      }
  
      public static ApplicationComponent getComponent() {
          return component;
      }
  </code></pre>