Android
kotlin + dagger2 + shared preferences
aucd29
2018. 12. 11. 17:24
test code 작성 중 java 로 코딩 되어 있는 AppModule 에 @Provides 를 kotlin 으로 변환하려고 하는데
예상치로는 아래와 같았지만 계속 되는 컴파일 오류 =_ =;;
@Module
abstract class AppModule {
@Binds
@Singleton
abstract fun provideContext(app: Application): Context
companion object {
@JvmStatic
@Provides
fun provideSharedPreference(context: Context) =
PreferenceManager.getDefaultSharedPreferences(context)
}
}
혹시나해서 찾아보니 (https://stackoverflow.com/questions/48081881/dagger-2-not-injecting-sharedpreference)
companion object 에도 @Module 을 추가해주어야하는 것
@Module
abstract class AppModule {
@Binds
@Singleton
abstract fun provideContext(app: Application): Context
@Module
companion object {
@JvmStatic
@Provides
fun provideSharedPreference(context: Context) =
PreferenceManager.getDefaultSharedPreferences(context)
}
}
예상치로는 아래와 같았지만 계속 되는 컴파일 오류 =_ =;;
@Module
abstract class AppModule {
@Binds
@Singleton
abstract fun provideContext(app: Application): Context
companion object {
@JvmStatic
@Provides
fun provideSharedPreference(context: Context) =
PreferenceManager.getDefaultSharedPreferences(context)
}
}
혹시나해서 찾아보니 (https://stackoverflow.com/questions/48081881/dagger-2-not-injecting-sharedpreference)
companion object 에도 @Module 을 추가해주어야하는 것
@Module
abstract class AppModule {
@Binds
@Singleton
abstract fun provideContext(app: Application): Context
@Module
companion object {
@JvmStatic
@Provides
fun provideSharedPreference(context: Context) =
PreferenceManager.getDefaultSharedPreferences(context)
}
}