Skip to content

Commit d89264f

Browse files
committed
Hilt: add small migration guide
1 parent b6501ce commit d89264f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/hilt_migration.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Useful links:
2+
- https://dagger.dev/hilt/migration-guide
3+
- https://dagger.dev/hilt/quick-start
4+
5+
Hilt is built on top of Dagger 2 and simplify usage by removing needs to create components manually.
6+
7+
When you create a new feature, you should have the following:
8+
9+
Annotate your Activity with @AndroidEntryPoint
10+
If you have a BottomSheetFragment => Annotate it with @AndroidEntryPoint
11+
Otherwise => Add your Fragment to the FragmentModule
12+
Add your ViewModel.Factory to the MavericksViewModelModule
13+
Makes sure your ViewModel as the following code:
14+
15+
```
16+
@AssistedFactory
17+
interface Factory: MavericksAssistedViewModelFactory<MyViewModel, MyViewState> {
18+
override fun create(initialState: MyViewState): MyViewModel
19+
}
20+
21+
companion object : MavericksViewModelFactory<MyViewModel, MyViewState> by hiltMavericksViewModelFactory()
22+
```
23+
24+
## Some remarks
25+
26+
@MavericksViewModelScope dependencies can't be injected inside Fragments/Activities
27+
You can only inject @Singleton, @MavericksViewModelScope or unscoped dependencies inside Maverick ViewModels
28+
You can access some specific dependencies from Singleton component by using
29+
```
30+
context.singletonEntryPoint()
31+
```
32+
Be aware that only the app has been migrated to Hilt and not the SDK.
33+

0 commit comments

Comments
 (0)