Skip to content

Instantly share code, notes, and snippets.

@juliuscanute
Created July 9, 2019 06:51
Show Gist options
  • Save juliuscanute/87dd28f839598cadf55be9b16ac0bd2f to your computer and use it in GitHub Desktop.
Save juliuscanute/87dd28f839598cadf55be9b16ac0bd2f to your computer and use it in GitHub Desktop.
Dictionary Module - DI
private const val BASE_URL = "https://dictionary-sample.azurewebsites.net/"
const val PAGE_SIZE = 20
val dictionaryModule = module {
single { createApiClient() }
single { DictionaryRepository(get()) as Repository }
single { PagedList.Config.Builder().setPageSize(PAGE_SIZE).setEnablePlaceholders(false).build() }
single { MutableLiveData<Event<NetworkState>>() }
factory { DictionaryAllWordsDataSourceFactory(get(), get()) }
factory { DictionarySearchWordsDataSourceFactory(get(), get()) }
viewModel { MainActivityViewModel(get(), get(), get(), get()) }
}
private fun createApiClient(): DictionaryApi {
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(MoshiConverterFactory.create())
.build()
return retrofit.create(DictionaryApi::class.java)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment