Does anyone know how to get an instance while in t...
# kodein
a
Does anyone know how to get an instance while in the Kodein builder context? I’ve tried finding the solution online, but can’t see anything in the docs. eg. The
configModule
has a
bind<Config>() with instance { Config(…) }
binding. I want to be able to use the instance of
Config
in the
databaseModule
which was set in the
configModule
.
Copy code
val kodein = Kodein {
  import(configModule())
  import(databaseModule(instance())
}
The
instance()
has a compiler-level warning because it can’t use the
KodeinAware.instance()
function - is there a different function to use here? cc: @salomonbrys
s
You can't. The container isn't created.
a
Ahh, that was the conclusion I was drawing to - guess I’ll just have to pass objects around. Thanks for getting back to me 🙌
s
@Alex What you could do is create a first kodein container with the config module only, then create a second container that
extends
the first container, use this first container to get the
Config
instance, then only use the second container in your app.
🙌 1