Last active
December 13, 2020 10:40
-
-
Save jobinlawrance/3df191e286310a15402660287a7c01f3 to your computer and use it in GitHub Desktop.
Sample Application setup when using Koin Library (code might not compile)
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
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