DaggerAppComponent не разрешается при реализации HasActivityInjector в приложении - PullRequest
0 голосов
/ 27 августа 2018

Когда я пытался использовать кинжал для предоставления Dao для своей базы данных комнаты, DaggerAppComponent генерируется в первый раз, но когда я реализую HasActivityInjector в моем Приложении, он внезапно становится неразрешенным. вот код:

Заявка:

class StudentApplication : Application(), HasActivityInjector{

@Inject lateinit var activityInjector: DispatchingAndroidInjector<Activity>
lateinit var appComponent: AppComponent
override fun onCreate() {
    super.onCreate()
    appComponent = DaggerAppComponent.builder().appModule(AppModule(applicationContext)).build()
    appComponent.inject(this)
}

override fun activityInjector(): DispatchingAndroidInjector<Activity> = activityInjector }

это AppModule

@Module
class AppModule (private val context: Context){
@Provides
fun provideContext() = context

@Provides @Singleton fun provideStudentDatabase(context: Context): StudentDatabase = Room.databaseBuilder(context,
        StudentDatabase::class.java, "studentdata.db")
        .build()

@Provides @Singleton fun provideStudentDao(studentDatabase: StudentDatabase) = studentDatabase.studentDao()

}

и это AppComponent:

 @Singleton
 @Component(modules = arrayOf(AppModule::class))
 interface AppComponent {
     fun inject(application: StudentApplication)
 }

Заранее спасибо, любая помощь будет оценена.

...