https://kotlinlang.org logo
Title
m

Max Kachinkin

02/27/2023, 4:34 PM
Hello, Kodein community! 👋 I’m wondering, what is your favourite Kodein feature or advantage? Why do you love using it? Especially compared to Koin DI, which is pretty much similar to Kodein in fundamentals and capabilities.
For me I can mention ConfigurableDI is pretty handy thing
i

ian.shaun.thomas

02/27/2023, 4:39 PM
Koin error messages leave a lot to desire especially around circular dependency issues. Much prefer using kodein.
r

rocketraman

02/28/2023, 2:39 PM
@Max Kachinkin How do you leverage
ConfigurableDI
i.e. what use case does it solve?
m

Max Kachinkin

02/28/2023, 5:10 PM
Hey @rocketraman! My use case is to config (
addConfig
,
addImport
) my DI in Android Initializers. It is from androidx.startup package. Separate Android module can have it’s Initializer and on creating itseft it can add it’s dependencies to DI
Something like this
class MyInitializer : Initializer<Unit> {
  override fun create(context: Context) {
    val module = DI.Module("myModule") {
      ...
    }
    ((context as DIAware).di as ConfigurableDI).addImport(module)
  }
}
But It has its cost. Decoupling your code like this it’s even much easier to forget to add binding of something (as we don’t have graph integrity safety)
And what is your favorite thing?
r

rocketraman

02/28/2023, 5:22 PM
Ah that would be great for a plug-in type architecture with
Set
bindings.
Not sure I have a favorite. It generally just works. Lots of integration points, customizability, easy and clean to configure (especially with the
new
function recently added, inspired by Koin), Seems relatively performant at startup time, though I wonder if KSP could help improve this even more in the future by moving some runtime init to compile time.
m

Max Kachinkin

02/28/2023, 5:28 PM
Oh, I found this
new
API that you suggested earlier! Thanks for this!) Yesterday I simplified my bindings with it.
I even wrapped it with own wrappers 🙂 So instead of this:
bind<Repository>() with singleton { new(::RepositoryImpl) }
I write this:
bind<Repository>() with singletonOf(::RepositoryImpl)