Endre Deak
10/25/2021, 3:53 PM// structures
interface Foo<T> { ... }
class FooInt : Foo<Int> { ... }
class FooString : Foo<String> { ... }
interface Bar<T> { val foo: Foo<T> }
class BarInt(val foo: Foo<Int>): Bar<Int> { ... }
class BarString(val foo: Foo<String>): Bar<String> { ... }
class Baz(val barInt: Bar<Int>, var barString: Bar<String>) { ... }
// qualifiers
object Qualifiers {
val fooInt = named("fooInt")
val fooString = named("fooString")
val barInt = named("barInt")
val barString = named("barString")
}
val module = module {
single(Qualifiers.fooInt) { FooInt() as Foo<Int> }
single(Qualifiers.fooString) { FooString() as Foo<String> }
single(Qualifiers.barInt) { BarInt(get(Qualifiers.fooInt)) as Bar<Int> }
single(Qualifiers.barString) { BarString(get(Qualifiers.fooString)) as Bar<String> }
single() { Baz(get(Qualifiers.barInt), get(Qualifiers.barString)) }
}
I try to inject interfaces everywhere, but it seems that
• without named qualifiers
• AND generic conversion (e.g. as Foo<int>
which btw marked as redundant by IntelliJ)
I get a failure of
Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'Foo' & qualifier:'fooInt'. Check your definitions!
This is really verbose and redundant, so I’m looking for some suggestions how can I make this shorter.