Im pretty new in Android development and newer in DI. I am using Kotlin on a personal project where I am experimenting with Dagger 2. I managed to set it up for a util class
You can try modifying your App module like this.
@Module
class ApplicationModule(private val application: Application) {
@Provides
@Singleton
fun provideContext(): Context {
return application.applicationContext
}
@Provides
@Singleton
fun provideSharedPreferences(context: Context): SharedPreferences {
return context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE)
}
}
Then you can build the dagger component like this from your Application class.
val appComponent = DaggerAppComponent.builder()
.applicationModule(ApplicationModule(this))
.build()
Inject values in presenter like this.
application.appComponent.inject(this)