We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basically, the following code doesn't work. I'm trying to create a ViewModel with a type parameter using assisted inject, but it fails with
[ksp] .../MyApplication/app/src/main/java/com/example/myapplication/Component.kt:17: Mismatched @Assisted parameters. Expected: [savedStateHandle: androidx.lifecycle.SavedStateHandle, provider: TypedProvider] But got: [androidx.lifecycle.SavedStateHandle, com.example.myapplication.TypedProvider<kotlin.String>]
@Component abstract class Component { abstract val viewModel: (SavedStateHandle, TypedProvider<String>) -> TypedViewModel<String> } @Inject object Singleton @Inject class TypedViewModel<Type>( singleton: Singleton, @Assisted savedStateHandle: SavedStateHandle, @Assisted provider: TypedProvider<Type>, ) interface TypedProvider<Type> { fun generate(): Type }
There is a workaround by doing an inner factory class instead, but this feels like something that should be supported.
abstract class Component { abstract val viewModel: (SavedStateHandle) -> TypedViewModel.Factory } class TypedViewModel(...) { @Inject class Factory( private val singleton: Singleton, @Assisted private val savedStateHandle: SavedStateHandle ) { fun <Type> provide(provider: TypedProvider<Type>) = TypedViewModel(singleton, savedStateHandle, provider) } }
The text was updated successfully, but these errors were encountered:
Same happen for me, here is my samples:
@Inject class HomeViewModel( @Assisted handle: SavedStateHandle, private val tickersPuller: TickersPullService, ) : ViewModel() { companion object { private const val TAG = "HomeViewModel" } }
Then I have component to inject view model later:
@Component interface HomeComponent { val homeViewModel: (SavedStateHandle) -> HomeViewModel }
But when I'm doing actual inject with:
appDiComponent.homeViewModel(SavedStateHandle.createHandle(null, null))
I got this error:
e: [ksp] Mismatched @Assisted parameters. Expected: [handle: SavedStateHandle] But got: [SavedStateHandle] e: Error occurred in KSP, check log for detail
Is it bug of library or am I do something wrong ?
Sorry, something went wrong.
@evant hi, i'm sorry for botherin you, but is there any update on this issue ?
No branches or pull requests
Basically, the following code doesn't work. I'm trying to create a ViewModel with a type parameter using assisted inject, but it fails with
There is a workaround by doing an inner factory class instead, but this feels like something that should be supported.
The text was updated successfully, but these errors were encountered: