Skip to content

Instantly share code, notes, and snippets.

@alibahaaa
Created June 25, 2022 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alibahaaa/ec626c6f06d181341e82e19a90a9449b to your computer and use it in GitHub Desktop.
Save alibahaaa/ec626c6f06d181341e82e19a90a9449b to your computer and use it in GitHub Desktop.
import org.koin.core.Koin
import org.koin.core.context.startKoin
import org.koin.core.parameter.parametersOf
import org.koin.dsl.KoinAppDeclaration
import org.koin.dsl.module
import kotlin.reflect.KClass
fun initKoin(appDeclaration: KoinAppDeclaration = {}) = startKoin {
appDeclaration()
modules(commonModule, platformModule())
}
fun initKoin() = initKoin {}
val commonModule = module {
single { createJson() }
single { createHttpClient(get()) }
single<RemoteDatasource> { RemoteDatasourceImpl(get()) }
single<Repository> { RepositoryImpl(get()) }
single { GetOrigamiUseCase(get()) }
}
fun <T> Koin.getDependency(clazz: KClass<*>): T {
return get(clazz, null) { parametersOf(clazz.simpleName) } as T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment