hamutarto
07/12/2019, 7:30 PMorg.kodein.di.Kodein$NotFoundException: No binding found for bind<SharedPreferences>() with ? { ? }
Available bindings for this type:
module androidModule {
bind<SharedPreferences>() with contexted<Context>().factory { String -> SharedPreferences }
bind<SharedPreferences>() with contexted<Context>().provider { SharedPreferences }
}
Registered in this Kodein container:
module analyticsModule {
bind<Analytics>() with singleton { AnalyticsImpl }
}
....
module apiM
I tried to solve it by manually bind SharedPreferences, without any luck
bind<SharedPreferences>() with singleton { PreferenceManager.getDefaultSharedPreferences(instance()) }
but what I eventually do (as I need Android Context as well for injection) is to use androidXmodule in the Application object. However the issue is still coming
override val kodein = Kodein.lazy {
import(androidXModule(this@MainApplication))
import(generalModule)
import(repositoryModule)
import(viewModelModule)
import(appSettingsModule)
import(apiModule)
import(useCaseModule)
import(analyticsModule)
import(locationModule)
import(dataSourceModule)
}
Please help me! I can’t find the solutiondrew
07/12/2019, 7:47 PMbind<SharedTokenManager>() with singleton {
val context = instance<Context>()
val sharedPrefs = on(context).instance<SharedPreferences>("tokens")
SharedTokenManager(sharedPrefs)
}
hamutarto
07/12/2019, 7:52 PMhamutarto
07/12/2019, 7:53 PMhamutarto
07/12/2019, 8:25 PMdrew
07/12/2019, 8:30 PMon(context).instance<SharedPreferences>("tokens")
drew
07/12/2019, 8:31 PMdrew
07/12/2019, 8:31 PMval inflater: LayoutInflater by kodein.on(context = getActivity()).instance()
hamutarto
07/13/2019, 7:26 AMCaused by: org.kodein.di.Kodein$NotFoundException: No binding found for bind<SharedPreferences>(tag = "settings") with ?<Context>().? { ? }
hamutarto
07/13/2019, 7:26 AMhamutarto
07/13/2019, 7:41 AM