Using Inject and AssistedInject together

Viewed 511

I'm writing an app using Dagger-Hilt for dependency injection. In my viewmodel, I already have an @Inject for the repo. Now, I want to add an @AssistedInject for the savestatehandle, but I keep getting an error if I use either one of them or use both of them together.

Is there a way I can use them both together? Thank you

@HiltViewModel
class DaoViewModel @Inject @AssistedInject constructor(private val repository: MoviesFavoritesRepository,
                                                       @Assisted private val state: SavedStateHandle) :
    ViewModel() {


1 Answers

You'd only use @AssistedInject. Because you can't inject something that requires an assistance, you don't have all the data ready. If you did, there'd be no reason to use an assisted inject.

Related