What I understand from the documentation, generics...
# koin
a
What I understand from the documentation, generics are supported only by giving a name to the
single
Copy code
module {
  single("foo") { Repository<Foo>() }
  single("bar") { Repository<Bar>() }
}

val fooRepo: Repository<Foo>() by inject("foo")
val barRepo: Repository<Bar>() by inject("bar")
Is there an alternative that I could use
inject()
(without key) instead of making the injector aware what the key should be?
t
Generics are not available at runtime, that is why
name
was introduced
I am not sure that there is alternative way to have it without params in
inject()
. With params - is to use module namespaces.
a
Ok thanks, I will build something around it
d
You could typealias your generics and inject the typealias - it’s still a little more code, but I’ve done it that way injecting rx subjects and such
t
I almost sure that typealiases don't exist at runtime too, they are just syntactic sugar for compiler
d
hm. maybe i just got lucky and wasn’t injecting multiple subjects