Skip to content

Instantly share code, notes, and snippets.

@msomu
Created June 25, 2020 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msomu/48ccb78ce3a4fb079e2fca1f8c2e6928 to your computer and use it in GitHub Desktop.
Save msomu/48ccb78ce3a4fb079e2fca1f8c2e6928 to your computer and use it in GitHub Desktop.
Learn all about Hilt here

Hilt

  • 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.

Why DI?

By following the principles of DI, you lay the groundwork for good app architecture.

  • Reusability of code
  • Ease of refactoring
  • Ease of testing

Hilt is built on top of Dagger

  • 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()
}

Resource

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment