From 3295d204b924aa72f81157f2c5082700b3f988c4 Mon Sep 17 00:00:00 2001 From: manu Date: Mon, 26 Feb 2024 00:32:45 +0100 Subject: [PATCH] Removed reflection remainings --- README.md | 96 +++++------------------------------------------ gradle.properties | 5 +-- 2 files changed, 11 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index eba7b9760..e15f74a7d 100644 --- a/README.md +++ b/README.md @@ -1,104 +1,28 @@ # Injekt Next gen dependency injection library for Kotlin. -# Coffee maker sample from Dagger: ```kotlin -/** The main app responsible for brewing the coffee and printing the logs. */ -fun main() { - val maker = inject() - val logger = inject() - - maker.brew() - logger.logs.forEach { println(it) } -} - -/** singleton scope */ -object SingletonScope -@Provide val singletonScope = Scope() - -/** A logger to logs steps while brewing coffee. */ -@Provide @Scoped class CoffeeLogger { - private val _logs = mutableListOf() - val logs: List get() = _logs.toList() - - fun log(msg: String) { - _logs += msg - } -} - -/** A coffee maker to brew the coffee. */ -@Provide class CoffeeMaker( - private val logger: CoffeeLogger, - heater: () -> Heater, - private val pump: Pump, -) { - private val heater by lazy(heater) // Create a possibly costly heater only when we use it. - - fun brew() { - heater.on() - pump.pump() - logger.log(" [_]P coffee! [_]P ") - heater.off() - } -} - -/** A heater to heat the coffee. */ -interface Heater { - fun on() - fun off() - val isHot: Boolean -} +@Provide fun jsonParser() = JsonParser() -/** An electric heater to heat the coffee. */ -@Provide @Scoped class ElectricHeater(private val logger: CoffeeLogger) : Heater { - override var isHot = false - private set +interface Http - override fun on() { - isHot = true - logger.log("~ ~ ~ heating ~ ~ ~") - } +@Provide class RealHttp : Http - override fun off() { - isHot = false - } -} +@Provide class Api(private val http: Http, private val jsonParser: JsonParser) -/** A pump to pump the coffee. */ -interface Pump { - fun pump() -} +@Provide class Repository(private val api: Api) -/** A thermosiphon to pump the coffee. */ -@Provide class Thermosiphon(private val logger: CoffeeLogger, private val heater: Heater) : Pump { - override fun pump() { - if (heater.isHot) - logger.log("=> => pumping => =>") - } -} +val repo = inject() ``` # Setup ```kotlin -// in your gradle.properties -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 \ - -Dkotlin.daemon.jvm.options=--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.reflect=ALL-UNNAMED \ - --add-opens=java.base/java.lang=ALL-UNNAMED \ - --add-opens=java.base/java.lang.reflect=ALL-UNNAMED - -// in your buildscript -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("com.ivianuu.injekt:injekt-gradle-plugin:${latest_version}") - } +plugins { + id("com.ivianuu.injekt") version latest_version } -// in your app module -plugins { - apply("com.ivianuu.injekt") +repositories { + mavenCentral() } dependencies { diff --git a/gradle.properties b/gradle.properties index 4f03c3ea6..d2b48a683 100755 --- a/gradle.properties +++ b/gradle.properties @@ -18,10 +18,7 @@ org.gradle.caching=true org.gradle.configuration-cache=false org.gradle.parallel=true -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 \ - -Dkotlin.daemon.jvm.options=--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.reflect=ALL-UNNAMED \ - --add-opens=java.base/java.lang=ALL-UNNAMED \ - --add-opens=java.base/java.lang.reflect=ALL-UNNAMED +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 POM_DEVELOPER_URL=https\://github.com/IVIanuu POM_LICENCE_URL=https\://www.apache.org/licenses/LICENSE-2.0.txt