Is there any way to shorten the boiler-plate requi...
# kodein
r
Is there any way to shorten the boiler-plate required for binding singletons where all the dependencies are coming from Kodein e.g.
Copy code
// replace
bindSingleton { Foo(instance(), instance(), instance(), instance(), instance()) }
// with something like this
bindSingleton { ::Foo }
r
Actually, no. Not with using constructor parameter. You could use the
DIAware
interface to manage on site retrieval instead of constructor injection
r
I don't like the
DIAware
approach because it ties my code to Kodein-DI. I'm a firm believer in the DI system being decoupled from the underlying code. I'd rather keep the boiler-plate.
How is the Koin team pulling this off? Are they using a compiler plugin or something?
r
I didn’t take a look at
but I don’t think so
this is ACTUALLY not possible with Kodein-DI
but it could
feel free to post an issue on github 😉
r
No magic here https://github.com/InsertKoinIO/koin/blob/3.2.x/core/koin-core/src/commonMain/kotlin/org/koin/core/module/dsl/New.kt I am not sure that we want to do the same. Defining a fixed number of function with N parameter is arbitrary. I have to think about it.
r
Makes sense. This pattern is not uncommon. For example, the Kotlin stdlib has
Function0
through
Function22
, and in fact the
::Foo
syntax returns a
KFunctionN
. Rxjava has http://reactivex.io/RxJava/3.x/javadoc/index.html?io/reactivex/rxjava3/functions/Function5.html. And so on.
Just tried it out with creating similar extensions for KodeinDI locally, and I have to admit, it does simplify the module definitions quite a bit.
r
Sounds fair. I’ll see when I will see what I can do to implement this.
👍 2
t
@rocketraman could you please post these extensions?
r
t
Thank youu
r
I've been very happy with it -- it really cleans up the module definitions, and often eliminates any diffs in the DI logic completely
t
I really like it! For the same reason.