Korinject Documentation
-
Are there any tutorials about korinject library? I would like to learn more about this library , can you please give me some guidance?
-
There is an issue here: https://github.com/korlibs/korlibs.soywiz.com/issues/25
Basically the injector supports mapping instances or factories (for multiple instances or singleton instances) like this:
https://github.com/korlibs/korge-samples/blob/e2b05052804e14023598d3948a295a442cc47bfd/scenes/src/commonMain/kotlin/main.kt#L19-L21injector.mapInstance(myConfig) injector.mapPrototype { MyScene(get(), get(), get()) } // as many get() as parameters have the main constructor injector.mapSingleton { MyService(get(), get(), get()) }
Then you can later get the instances:
val scene1 = injector.get<MyScene>() // two different insances val scene2 = injector.get<MyScene>() // two different insances val myService = injector.get<MyService>() // the same singleton instance val myServiceAgain = injector.get<MyService>() // the same singleton instance
And that's it. You can create child injectors, but the injector itself is super simple.