Do I definitely need to get my viewmodel from a vi...
# android
j
Do I definitely need to get my viewmodel from a viewmodelprovider? Right now I'm doing it like this:
Copy code
@Provides
    @MainScope
    fun contributeViewModel(isSignedInUseCase: IsSignedInUseCase, signOutUseCase:SignOutUseCase, toolbarViewConfig: ToolbarViewConfig): MainActivityViewModel =
        MainActivityViewModel(isSignedInUseCase, signOutUseCase, toolbarViewConfig)
and then I build it in MainActivity using my builder, and then I can access the viewmodel there.
Copy code
interface MainComponent {
    fun mainViewModel(): MainActivityViewModel
    fun navController(): NavController

    @Component.Builder
    interface Builder {
        fun build(): MainComponent

        @BindsInstance
        fun activity(activity: AppCompatActivity): Builder
        fun coreComponent(coreComponent: CoreComponent): Builder
    }

}
Am I missing something? Will the viewmodel not be provided to me in the same way using this method? Here's how I use it in MainActivity:
Copy code
mainComponent = DaggerMainComponent
            .builder()
            .coreComponent(coreComponent)
            .activity(this)
            .build()

        mainActivityViewModel = mainComponent.mainViewModel()
🤦‍♂️ 3
d
This is not related to Kotlin, please check this channel topic