Newer
Older
DevAndroid / app / src / main / java / keijumt / devandroid / di / module / ViewModelModule.kt
KeijuMatsumoto on 21 May 2018 857 bytes Updated file name
package keijumt.devandroid.di.module

import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import dagger.Binds
import dagger.MapKey
import dagger.Module
import dagger.multibindings.IntoMap
import keijumt.devandroid.viewmodel.ApiViewModel
import keijumt.devandroid.viewmodel.ViewModelFactory
import kotlin.reflect.KClass

@MustBeDocumented
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
@MapKey
internal annotation class ViewModelKey(val value: KClass<out ViewModel>)

/**
 * Module: ViewModel 定義
 */
@Module
internal abstract class ViewModelModule {

    @Binds
    @IntoMap
    @ViewModelKey(ApiViewModel::class)
    abstract fun bindApiViewModel(viewModel: ApiViewModel): ViewModel

    @Binds
    abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory

}