The difference between Dagger1 and Dagger2 and Hilt

Dagger1, Dagger2 and Hilt are all dependency injection frameworks in Android development, and their differences are as follows:

  • Dagger1 is the earliest version, which uses the reflection mechanism to implement dependency injection. It has poor performance and is not recommended.
  • Dagger2 is an upgraded version of Dagger1. It uses annotation processor (APT) to generate auxiliary code, avoids reflection, and improves performance a lot. However, it is still complicated to use and requires writing a lot of template code and configuration.
  • Hilt is a secondary package based on Dagger2. It uses annotation processor (APT) and bytecode manipulation (ASM) to generate auxiliary code, which simplifies the use of Dagger2. It does not need to manually create components and modules, just add Appropriate annotations are sufficient. Hilt is also part of Android Jetpack and is more compatible with other Jetpack components. In general, Hilt is an order of magnitude better dependency injection framework than Dagger2.

Guess you like

Origin blog.csdn.net/challenge51all/article/details/130642973