Skip to content

Instantly share code, notes, and snippets.

View romainbsl's full-sized avatar

Romain Boisselle romainbsl

View GitHub Profile
@romainbsl
romainbsl / ktor-kodein-controller-example.kt
Last active June 3, 2019 05:27
Ktor with Kodein controller example
import io.ktor.application.*
import io.ktor.auth.*
import io.ktor.response.respondText
import io.ktor.routing.*
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import org.kodein.di.Kodein
import org.kodein.di.generic.*
import org.kodein.di.ktor.*
import org.kodein.di.ktor.controller.*
@romainbsl
romainbsl / types.kt
Created January 27, 2020 20:14
Kodein-DI TypeToken Native
@UseExperimental(ExperimentalStdlibApi::class)
inline fun <reified T> generic(): TypeToken<T> = NativeKTypeToken(typeOf<T>())
@UseExperimental(ExperimentalStdlibApi::class)
inline fun <reified T: Any> TT(obj: KClass<T>) : TypeToken<T> = NativeKTypeToken(typeOf<T>())
@UseExperimental(ExperimentalStdlibApi::class)
inline fun <reified T: Any> TTOf(obj: T) : TypeToken<T> = NativeKTypeToken(typeOf<T>())
// Bindings
val kodeinContainer = Kodein {
bind() from singleton { MyController() }
constant("creator") with ("Salomon BRYS")
constant("maintainer") with ("Romain BOISSELLE")
}
// Kodein Aware application
class DemoApplication(override val kodein: Kodein)
: Application(), KodeinAware {
// ...
// Bindings
val diContainer = DI {
bind() from singleton { MyController() }
constant("creator") with ("Salomon BRYS")
constant("maintainer") with ("Romain BOISSELLE")
}
// Kodein Aware application
class DemoApplication(override val di: DI)
: Application(), DIAware {
// ...
@romainbsl
romainbsl / build.gradle.kts
Last active June 1, 2020 14:27
kodein-di-v6-android-gradle
implementation("org.kodein:kodein-di-framework-android-x:6.5.5")
implementation("org.kodein:kodein-di-generic-jvm:6.5.5")
@romainbsl
romainbsl / build.gradle.kts
Last active June 1, 2020 14:22
kodein-di-v6-gradle.kt
// API use
implementation("org.kodein:kodein-di-core:6.5.5")
// Generic, JVM only use
implementation("org.kodein:kodein-di-generic-jvm:6.5.5")
// Erased, Native, JS or even JVM use
implementation("org.kodein:kodein-di-erased:6.5.5")
@romainbsl
romainbsl / build.gradle.kts
Last active June 1, 2020 14:21
kodein-di-v7-android-gradle
implementation("org.kodein:kodein-di-framework-android-x:7.0.0")
@romainbsl
romainbsl / build.gradle.kts
Last active June 1, 2020 14:23
kodein-di-v7-gradle
// Whatever is your target
implementation("org.kodein.di:kodein-di:7.0.0")
/**
* Simple token auth to avoid flood on my backend API
*/
data class Token(val token: String) {
fun bearer() = "Bearer $token"
}
/**
* Who's voting?
plugins {
kotlin("multiplatform") version "1.3.72"
kotlin("plugin.serialization") version "1.3.72"
`maven-publish`
}
kotlin {
jvm("android")
ios()