Shawxing Kwok
11/28/2023, 10:16 AMJavier
11/28/2023, 11:53 AMLeoColman
11/28/2023, 11:57 AMTracer has several main advantages over common DI tools, as listed below:
Minimal configuration. Powerful: generic types and variances are parsable, and it can trace super types as well.But it's a bit too abstract for my mind
Shawxing Kwok
11/28/2023, 12:04 PMTracer
to implement generated interfaces. I hope one day Tracer
is integrated into Kotlin system as the new syntax.
2. It's too long to make a true comparison. In a big project, Koin, KodeIn, Dagger/Hilt should care about lifecylcles, and maybe dependency cycles further.Javier
11/28/2023, 12:17 PMShawxing Kwok
11/28/2023, 12:17 PMJavier
11/28/2023, 12:18 PMroot class House
nodes(House)
class Bedroom{
val bed = Bed()
}
tracer(Bedroom)
class Bed{
private val house get() = __House
}
Javier
11/28/2023, 12:19 PMStefan Oltmann
11/28/2023, 12:24 PMShawxing Kwok
11/28/2023, 12:25 PMnodes class Bedroom
and makes Bedroom
implement BedroomTracer
automatically.
Although context receiver
is not adaptable on Kotlin-JS and Kotlin-Native at present, they are realizable theoretically.Javier
11/28/2023, 12:25 PMclass House
context(House)
class Bedroom {
val bed = Bed()
// generated somewhere
val __House get() = this@House
}
context(Bedroom)
class Bed {
// generated somewhere
private val __House get() = __House
}
Javier
11/28/2023, 12:26 PMAlthough context receiver is not adaptable on Kotlin-JS and Kotlin-Native at present, they are realizable theoretically.That is because it isn't finished yet, the final implementation will work with all targets
Javier
11/28/2023, 12:28 PMWith my expected Tracer syntax, there hints you to build when you finish inputting nodes(Bedroom) and makes Bedroom implement BedroomTracer automatically.You don't need a new keyword for that anyway, an annotation is enough
Shawxing Kwok
11/28/2023, 12:28 PMcontext(Bedroom)
keeps the same. But @Nodes class Bedroom : BedroomTracer
changes to nodes class Bedroom
. Next Kotlin plugin hints at you to build.Javier
11/28/2023, 12:29 PMnodes(Beedroom) Bed
would be exactly the same as @Node context(Bedroom) class Bed
inside a compiler plugin if I am not missing anything. No need for a new keyword.Javier
11/28/2023, 12:31 PM@Node
Shawxing Kwok
11/28/2023, 12:33 PMYou can add any supertype you want automatically based on an annotation, in this case,It's different from your expected compiler plugin. Because the interface generates after building.@Node
Javier
11/28/2023, 12:34 PMShawxing Kwok
11/28/2023, 12:35 PMThat is not correct, with K2 you can add the supertype in frontend (FIR)
Javier
11/28/2023, 12:35 PMShawxing Kwok
11/28/2023, 12:35 PMThat is not correct, with K2 you can add the supertype in frontend (FIR)Ok, I will learn further and optimize
Tracer
. Thx!Javier
11/28/2023, 12:39 PMShawxing Kwok
11/28/2023, 12:41 PMMain issue is you can do that with KSP, you need a compiler plugin using K2Got it! I appreciate your help.