From d89264ff7708503b0d82b7b530e6d5a414e0d690 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 22 Oct 2021 11:30:21 +0200 Subject: [PATCH] Hilt: add small migration guide --- docs/hilt_migration.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 docs/hilt_migration.md diff --git a/docs/hilt_migration.md b/docs/hilt_migration.md new file mode 100644 index 0000000000..50021e9792 --- /dev/null +++ b/docs/hilt_migration.md @@ -0,0 +1,33 @@ +Useful links: +- https://dagger.dev/hilt/migration-guide +- https://dagger.dev/hilt/quick-start + +Hilt is built on top of Dagger 2 and simplify usage by removing needs to create components manually. + +When you create a new feature, you should have the following: + +Annotate your Activity with @AndroidEntryPoint +If you have a BottomSheetFragment => Annotate it with @AndroidEntryPoint +Otherwise => Add your Fragment to the FragmentModule +Add your ViewModel.Factory to the MavericksViewModelModule +Makes sure your ViewModel as the following code: + +``` + @AssistedFactory + interface Factory: MavericksAssistedViewModelFactory { + override fun create(initialState: MyViewState): MyViewModel + } + + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() +``` + +## Some remarks + +@MavericksViewModelScope dependencies can't be injected inside Fragments/Activities +You can only inject @Singleton, @MavericksViewModelScope or unscoped dependencies inside Maverick ViewModels +You can access some specific dependencies from Singleton component by using +``` +context.singletonEntryPoint() +``` +Be aware that only the app has been migrated to Hilt and not the SDK. +