https://kotlinlang.org logo
#koin-contributors
Title
# koin-contributors
b

bobby

05/25/2020, 2:35 PM
Hi everyone, Recently I had tried to implement Koin in my project. After trying Koin, I realized how concise and simple the implementation is. The time for me to learn using Koin is pretty fast, comparing to Dagger 2. But there's something that keeps bothering me. I saw an article mentioned that Koin isn't using the DI pattern, rather it using the Service Locator pattern. My question is, why Koin use the Service Locator pattern? And is that matter which pattern to use? Thanks a lot.
a

arnaud.giuliani

05/29/2020, 2:20 PM
Koin is a DI framework in the sense that it allows you to constructor injection
the main subtile thing is that, people only see one thing
by inject()
this is the key of Koin, to unlock the service locator pattern to something that is smarter to write than a
lateinit var
injected property
the thing is, a
by inject()
will actively request the API to look at your instance
With dagger, your manually ask Dagger to inject your properties
but then, the drawback is that your property is linked to Koin directly, contrary to Dagger
but ...
this is only affecting Android classes (Activity/Fragment) that you can’t create directly by hand
perhaps my talk about Koin can help you: https://www.droidcon.com/media-detail?video=390453576
b

bobby

05/29/2020, 2:39 PM
I'll listen to the talk and think about your answers thoroughly, thanks
👍 1
2 Views