- Jetpack’s recommended library for Dependency Injection.
- Hilt is a new Android library which simplifies dependency injection in your application.
- Hilt lets you focus on just the important parts of defining and injecting without worrying about managing all of the DI setup and wiring.
By following the principles of DI, you lay the groundwork for good app architecture.
- Reusability of code
- Ease of refactoring
- Ease of testing
- Compile-time correctness
- Improved runtime performance
- Scalability
Hilt adds integration with Jetpack libraries and Android framework classes.
class SearchViewModel @ViewModelInject constructor(
private val repository: SearchRepository
): ViewModel() { /* .. */ }
@AndroidEntryPoint
class SearchFragment : Fragment() {
private val viewModel : SearchViewModel by viewModels()
}
- MyThoughts - My thoughts about Hilt on Twitter Thread
- Get Started - Developer.Android.com Getting started Guide on Hilt
- Dagger 2 - Best Video if you want to get started on Dagger 2
- Launch Blog post - Medium Article on Dependency Injection on Android with Hilt by Google Developers
- Code Lab - Using Hilt in your Android app
- Code Lab - Migrating your Dagger app to Hilt
- Exploring hilt - Learn about under the hood on Hilt.
- Cheat Sheet - Shows the different Hilt and Dagger annotations do and how to use them
Thanks you can follow me on Twitter at @msomuin