Skip to content

Instantly share code, notes, and snippets.

@harmittaa
Created July 13, 2019 18:03
Show Gist options
  • Save harmittaa/4cbd3c9529d7a7c25245124a4ac29d7c to your computer and use it in GitHub Desktop.
Save harmittaa/4cbd3c9529d7a7c25245124a4ac29d7c to your computer and use it in GitHub Desktop.
Koin 2.0 and Retrofit 2.6.0
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.github.harmittaa.koinexample.model.Weather
import com.github.harmittaa.koinexample.model.WeatherRepository
import org.koin.dsl.module
val viewModelModule = module {
factory { ExampleViewModel(get()) }
}
class ExampleViewModel(
private val weatherRepo: WeatherRepository
) : ViewModel() {
val weather: LiveData<Weather> = liveData {
emit(weatherRepo.getWeather())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment