if i were to add DI to an already established proj...
# android
m
if i were to add DI to an already established project, is it worth considering Koin at this point, or is Dagger 2 still the suggested route?
a
I looked through Koin the other day and was kind of disappointed. But I've also been frustrated with how difficult Dagger 2 has been to setup. Lately I've just been doing manual DI
d
that’s a fairly subjective question. which are you more familiar with?
m
Neither. I’ve been doing all my dependency management by hand, but I’m planning a larger refactor to decouple as much business logic as I can from the SDK (for the second time) and thought it might be time to look into it.
c
While I haven’t actually used Koin, it does look more like an abstraction over a Factory Pattern more than actual DI (it doesn’t implement the JSR330 interface for an injector). My guess is that it would be easier for initial setup and work well for small projects, but it just wouldn’t scale well for larger projects, and doesn’t automatically adapt to refactoring like a DI framework would. That being said, Dagger 2 took me a really long time to get set up correctly, but now that it’s in place, it was 100% worth the effort. The nature of code-gen makes it work a bit differently than a runtime DI framework like Spring or Guice, but once you wrap your mind around how it works and how to set it up, you really do use it in pretty much the same way as those runtime libs, just with significantly better performance. And unlike Koin, Dagger will scale infinitely for you and stands up against refactoring, and you’ll really start to notice the benefits when building an app with many independent modules.
👍 3
m
Thanks for the detailed response.
r
Dagger 2 is supported by Google , so it's definitely the preferred way... Koin isn't completely DI framework
j
I have been using Kodein and been very happy with it. I felt like Dagger had too much cruft, though I have always been wary of DI through attributes. But that's just personal preference, of course.
e
Thumb up for Kodein