У меня есть следующий модуль, в котором я создаю настройки общего доступа
@Module
@ComponentScan
class SharedPreferenceModule {
companion object {
private const val FILE_NAME = "secret_shared_prefs"
}
@Single
fun provideSharedPreferences(context: Context): SharedPreferences {
val masterKeys = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
return EncryptedSharedPreferences.create(
FILE_NAME,
masterKeys,
context,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
}
}
Я получаю следующую ошибку:
e: [ksp] --> Missing Definition type 'android.content.Context' for 'di.provideSharedPreferences'. Fix your configuration to define type 'Context'.
Я просто спрашиваю, почему я не могу аннотировать функцию с помощью @single?
В моем классе приложения у меня есть следующее:
р>
startKoin {
androidLogger()
androidContext(this@BusbyTravelMateApplication)
modules(
networkModule,
repositoryModule,
useCaseModule,
userModule,
SharedPreferenceModule().module
)
}
И я пытаюсь внедрить в этот класс
class UserTokenLocalDataSourceImp(private val encryptedSharedPreferences: EncryptedSharedPreferences)
: UserTokenLocalDataSource {
companion object {
private const val TOKEN = "token"
}
override suspend fun saveUserToken(token: String) {
encryptedSharedPreferences.edit {
this.putString(TOKEN, token)
this.apply()
}
}
override suspend fun fetchUserToken(): String? {
return encryptedSharedPreferences.getString(TOKEN, null)
}
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... ition-type