To sum up: ``` module { single { Simple.Compon...
# koin
a
To sum up:
Copy code
module {
    single { Simple.Component1() } bind Simple.ComponentInterface1::class
    single { Simple.Component2() } bind Simple.ComponentInterface1::class
    single { Simple.UserComponent(bind<Simple.Component1, Simple.ComponentInterface1>()) }
}
- you can get directly the instances with
get<Simple.Component1>()
,
get<Simple.Component2>()
-
get<Simple.ComponentInterface1>()
will throw an error and tell you to use
bind
because can’t choose between the 2 definitions - you can use
bind<>()
to resolve a component in the DSL -
getAll<Simple.ComponentInterface1>()
give us the 2 instances
s
So you can
val instance: Simple.ComponentInterface1 = bind<Simple.Component1, Simple.ComponentInterface1>()
, is that right?
a
yes
s
Cool, wasn't sure if I got it right
Then is there any difference between that and
val instance: Simple.ComponentInterface1 = get<Simple.Component1>()
? Or just different API?
a
in that case will be the same
k
Sounds good..not sure you need getAll() but doesn't hurt
a
getAll can be interesting to scan definitions tagged with the same type
if you have several definition of
Feature
or
Plugin
for example
can help to write dynamic behaviour
k
good point 🙂