Skip to content

Instantly share code, notes, and snippets.

@jobinlawrance
Last active December 13, 2020 10:40
Show Gist options
  • Save jobinlawrance/3df191e286310a15402660287a7c01f3 to your computer and use it in GitHub Desktop.
Save jobinlawrance/3df191e286310a15402660287a7c01f3 to your computer and use it in GitHub Desktop.
Sample Application setup when using Koin Library (code might not compile)
class HomeApplication: Application() {
internal lateinit var koinApplication: KoinApplication
override fun onCreate() {
super.onCreate()
koinApplication = startKoin {
androidContext(this@HomeApplication)
modules(apiModule, interactorModule, viewModelModule)
}
}
}
val apiModule = module {
single {
Retrofit.Builder()
.baseUrl("https://base-url-for-some-api.com")
...
.build()
.create(ApiService::class.java)
}
}
val interactorModule = module {
factory { HomeInteractor(get())} // --> class HomeInteractor (val apiService: ApiService)
factory { ... }
}
// These are AAC Viewmodels
val viewmoduleModuel = module {
viewModel { HomeViewModel(get) } // --> class HomeViewModel (val homeInteractor: HomeInteractor): ViewModel
viewModel { ... }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment