What's the difference between Dagger, Hilt and Koin under the hood?

Hello, Habr. For future students of the course "Android Developer. Professional" prepared a traditional translation of the material.



We also invite everyone to the webinar on the topic
"Profiling and speeding up Gradle builds" . During the lesson, the participants, together with an expert:

- learn how to find bottlenecks in assemblies using gradle-profiler, scan and visualVM;

- learn how to properly configure Gradle;

- will consider other possibilities for optimizing and speeding up assemblies on a large project.






Dagger and Koin are without a doubt the two most popular dependency injection frameworks on Android. Both of these libraries serve the same purpose and seem very similar, but they work in different ways.





Hilt? Hilt โ€” , Dagger , , Dagger, Hilt.





, . , , .





Dagger

, Dagger - , , , @Inject



.





, Dagger (Factory) . , โ€” CompositeAdapter



, CompositeAdapter_Factory



.





, CompositeAdapter



.





Snippet of code generated by Dagger
, Dagger

, get()



, CompositeAdapter



. , Provider, . Provider .





, Hilt Dagger?

. Hilt โ€” , Dagger , , , Dagger. Hilt, , Dagger , . .





Koin

Koin , Dagger , , Hilt. Koin, , Koin . , , .





Koin InstancesRegistry



, , .





map โ€” , , . โ€” , .





, , , get()



(, ) inject()



, get()



. get()



, , .





?

, Dagger , Koin โ€” .





1.

Dagger โ€” , - , , .





, @Inject



CompositeAdapter



, , , .





Dagger assembly output with missing @Inject annotation
Dagger @Inject

Koin . , CompositeAdapter



, , RuntimeException



, . , , , - - .





Koin throws exception when there is no factory for CompositeAdapter
Koin , CompositeAdapter

2.

, Koin , : . Dagger . .





3.

, Koin , .





? , , . , , .. - 4 .





Source: https://github.com/Sloy/android-dependency-injection-performance
: https://github.com/Sloy/android-dependency-injection-performance

, Dagger . , Koin , . Dagger , Koin.





, , , . Koin Dagger , . , , , , Dagger Koin, , -, , . , : Koin, Dagger Hilt .





, , , , , .






- "Android Developer. Professional".

-
"Android Developer. Basic".





ยซ Gradle ยป.








All Articles