I am quite new with android and have issue that I ...
# android
I am quite new with android and have issue that I do not know how to solve. I use Assisted injection with dagger hilt and I have ViewModelFactoryProvider that looks like this
Copy code
interface ViewModelFactoryProvider {
    fun communityFeedViewModelFactory(): CommunityFeedViewModel.Factory
    fun postTileViewModelFactory(): PostTileViewModel.Factory
    fun reactionViewModelFactory(): ReactionsViewModel.Factory
    fun commentViewModelFactory(): CommentViewModel.Factory
Here is for example how i use it in ReactionsViewModel
Copy code
class ReactionsViewModel
    @Assisted private var reactions: PostReactions,
    @Assisted private var postId: String,
    private var reactionsRepository: ReactionsRepository,
) : ViewModel() {

    interface Factory {
        fun create(
            @Assisted reactions: PostReactions,
            @Assisted postId: String,
        ): ReactionsViewModel

    companion object {
        fun provideFactory(
            assistedFactory: Factory,
            reactions: PostReactions,
            postId: String
        ): ViewModelProvider.Factory = object : ViewModelProvider.Factory {
            override fun <T : ViewModel> create(modelClass: Class<T>): T {
                return assistedFactory.create(reactions, postId) as T

fun reactionsViewModel(
    reactions: PostReactions,
    id: String
): ReactionsViewModel {
    val factory = EntryPointAccessors.fromActivity(
        LocalContext.current as Activity,
    return viewModel(
        factory = ReactionsViewModel.provideFactory(
            postId = id,
        ), key = id
And here is how I provide reactions respository:
Copy code
object ReactionsModule {
    fun provideReactionApi(retrofit: Retrofit):
            ReactionsApi = retrofit.create(ReactionsApi::class.java)

    fun providesRRepository(ReactionsApi: ReactionsApi):
            ReactionsRepository =
Problem here is that I need to use ActivityComponent in module where I provide repository. If i try to access this reactions repository in any other viewmodel it crash because it needs to be ViewModelComponent. Is there any clever solution how to fix it?
­čžÁ 2
­čśÂ 2