mariodroid
01/16/2018, 7:05 AMSharedPreferences
?
bind<Foo>() with provider {Foo(instance()) }
where my Foo
class requires in the constracture shared preferences
I add the module in this way:
kodein.addConfig {
import(androidModule)
BaseAppComponent()
}
Andreas Sinz
01/16/2018, 8:33 AMinstance()
should be enough to inject SharedPreference
into Foo
. What are you experiencing?mariodroid
01/16/2018, 10:54 PMConfigurableKodein
so I had to add the import by :
kodein.addImport(androidModule)
instead.. I just figured out it later, although the import it's done successfully it's not working anyway .. for instance to retrieve Resources
or SharedPreferences
I got
com.github.salomonbrys.kodein.Kodein$NotFoundException: No provider found for bind<Resources>() with ? { ? }
but in the list of binds I have
bind<Resources>() with factory { Context -> Resources }
which should be enough since I retrieve the instance through kodein.instance()
mariodroid
01/16/2018, 10:54 PMAndreas Sinz
01/17/2018, 8:54 AMResources
is bound with a factory
that requires a Context
as an argument. So you'd need to provide an instance of Context
to retrieve the Resources. You have two ways to resolve this problem. Either use instance(context)
to retrieve Resources
or use kodein.addImport(autoAndroidModule(context))
and then instance()
like you did beforemariodroid
01/17/2018, 9:50 AMmariodroid
01/22/2018, 6:00 AMmariodroid
01/22/2018, 6:03 AMcontext
instance that kodein with autoimport
would return me automatically the context from the app. I solved adding it to my component :
bind<Context>() with provider { App.context!! }
mariodroid
01/22/2018, 6:04 AMAndreas Sinz
01/22/2018, 9:04 AMautoAndroidModule(context)
instead of the androidModule
, that automatically binds the Context
and a lot of other stuff https://github.com/SalomonBrys/Kodein/blob/734f09ba0e8d80046beec92f29c928b46a4dfd23/kodein-android/src/main/java/com/github/salomonbrys/kodein/android/AndroidModule.kt#L212mariodroid
01/22/2018, 11:25 PMmariodroid
01/22/2018, 11:25 PMmariodroid
01/22/2018, 11:25 PMContext
Andreas Sinz
01/23/2018, 1:26 PMmariodroid
01/24/2018, 10:43 PMmariodroid
01/24/2018, 10:45 PMfun Kodein.Builder.BaseAppComponent() {
bind<Context>() with provider { App.context!! }
}
mariodroid
01/24/2018, 10:46 PMmariodroid
01/24/2018, 10:46 PMbind<AuthManager>() with provider { AuthManager(KodeinSharedPreferencesInfo(instance(), SP_AUTH).getSharedPreferences()) }
mariodroid
01/24/2018, 10:46 PM