title: How to provide Activity Context via Dagger 2 in an Android project?
body: <p>This is the code I have in my Activity.</p>
  
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_work_order)
          DaggerWorkOrderComponent.factory()
                  .create(activity)
                  .inject(activity)
  }
  </code></pre>
  
  <p>This is my module.</p>
  
  <pre><code>@Module
  object WorkOrderModule {
  
      private lateinit var context: Context
  
      fun setWorkOrderActivityContext(ctx: Context) {
          context = ctx
      }
  
      @Provides
      @JvmStatic
      fun provideContext(): Context = context
  
      @Provides
      @JvmStatic
      fun provideLogger(): Logger = getLogger()
  
      @Provides
      @JvmStatic
      fun provideAppDataManager(): AppDataManager = getAppDataManager()
  
      @Provides
      @JvmStatic
      fun provideFirebaseManager(): FirebaseManager = getFirebaseManager()
  
      @Provides
      @JvmStatic
      fun provideViewModel(
          logger: Logger,
          appDataManager: AppDataManager,
          firebaseManager: FirebaseManager
      ): WorkOrderVM = WorkOrderVM(context, logger, appDataManager, firebaseManager) // &lt;=== line 45
  }
  </code></pre>
  
  <p>and finally, this is my component.
  @FeatureScope</p>
  
  <pre><code>@Component(modules = [WorkOrderModule::class])
  interface WorkOrderComponent {
  
      @Component.Factory
      interface Factory {
          fun create(@BindsInstance context: Context): WorkOrderComponent
      }
  
      fun inject(activity: WorkOrderActivity)
  }
  </code></pre>
  
  <p>The application crashes and this is what I get:</p>
  
  <blockquote>
    <p>Caused by: kotlin.UninitializedPropertyAccessException: lateinit
    property context has not been initialized
            at com.atco.forsite.screens.inspection.workOrder.di.WorkOrderModule.provideViewModel(WorkOrderModule.kt:45)</p>
  </blockquote>
  
  <p>The line 45 has marked in the Module.</p>