This one is kinda out there, but I had an idea for...
# language-proposals
j
This one is kinda out there, but I had an idea for dependency injection in the language with a single modifier. It might look like this:
Copy code
kotlin
fun iHaveTooManyDependencies(
    @DI a: A,
    @DI b: B,
    @DI c: C,
    normalArg: Int = 0
) { /*...*/}

fun anotherWithALot(
    @DI a: A = DefaultA(),
    @DI b: B = DefaultB(),
    @DI c: C = DefaultC()
) {
    // Parameters a, b, and c are automatically placed because this function's parameters have @DI and the same name/type
    iHaveTooManyDependencies(normalArg = 3)
    // This is exactly equivalent to
    iHaveTooManyDependencies(a = a, b = b, c = c, normalArg = 3)

    // You can still pass them in as usual
    iHaveTooManyDependencies(a = MyWeirdAImplementation(), normalArg = 1)
}

class HavingDependencies(
    @DI val a: A = DefaultA(),
    @DI val c: C = DefaultC()
) {
    fun test(@DI b: B = DefaultB()){
        // Parameters a and c are automatically placed because this class has members that have @DI and the same name/type
        // Parameters b is automatically placed because this function's parameters have @DI and the same name/type
        iHaveTooManyDependencies()
        // Probably should pull from the closest scope by default
    }
}

fun fullTest(
    @DI a: A = DefaultA(),
    @DI c: C = DefaultC()
){
    //This works for constructors too
    HavingDependencies().test()
}