Created
July 9, 2019 06:51
-
-
Save juliuscanute/87dd28f839598cadf55be9b16ac0bd2f to your computer and use it in GitHub Desktop.
Dictionary Module - DI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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