Last active
June 26, 2024 13:16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We are using @AssistedInject instead | |
// of normal @Inject as we want | |
// to assist one dependency by our own | |
// at runtime and rest by hilt | |
@HiltViewModel(assistedFactory = MainViewModel.Factory::class) | |
class MainViewModel @AssistedInject constructor( | |
// dependency which is to be assisted by | |
// us should be annotated with @Assisted | |
@Assisted | |
private val query: String | |
) : ViewModel() { | |
// We define the factory of this viewmodel here., | |
// So we need to annotate this factory interface | |
// with @AssistedFactory in order to let Hilt | |
// know about it | |
@AssistedFactory | |
interface Factory { | |
fun create(query: String): MainViewModel | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment