hey hey! I'm trying to inject the SharedPreferenc...
# kodein
h
hey hey! I'm trying to inject the SharedPreferences from the androidCoreModule but i'm getting this error. Do you know why?
Copy code
org.kodein.di.Kodein$NotFoundException: No binding found for bind<SharedPreferences>() with ? { ? }
    Available bindings for this type:
            module ⁣androidModule {
                bind<SharedPreferences>() with contexted<Context>().provider { SharedPreferences }
                bind<SharedPreferences>() with contexted<Context>().factory { String -> SharedPreferences }
            }
    Registered in this Kodein container:
..
r
Hey. How did you try to inject the
SharedPreferences
item ? Did you set up a context to do so ?
h
I did not setup any binding for context in the app
I used
Copy code
import(androidCoreModule(this@MainApplication))
as far as I know it contains both of them
r
Yes, but as far as I understand how the Android modules are working, you might inject your
SharedPreferences
with a context
or even, define a context in your class by overriding the
kodeinContext
if you are in a
KodeinAware
class:
Copy code
override val kodeinContext = kcontext(androidContext) 
`
as the Android documentation says a context can be a lot of things https://developer.android.com/reference/android/content/Context
Copy code
AbstractInputMethodService, AccessibilityService, AccountAuthenticatorActivity, Activity, ActivityGroup, AliasActivity, Application, AutofillService, BackupAgent, BackupAgentHelper, CallRedirectionService, CallScreeningService, CameraPrewarmService, CarrierMessagingClientService, CarrierMessagingService, and 44 others.
so by injecting with a context you might get the right
SharedPreferences
https://kodein.org/Kodein-DI/?6.2/core#_defining_context
h
hmm that is strange, in my previous model it worked like a charm with the same declaration
can you show me a correct example for prividing Context? as it is not something that I create at bind time
r
I'm no Android developer, I'm just guessing solution to your problem by reading the documentation so far. do you have a repo to show us the code ?