Christian Dräger
12/28/2020, 10:44 AM// lets assume i have some basic crud repository like:
interface MyFunkyRepository : CrudRepository<MyFunkyEntity, String>
@Entity(name = "funky")
@Table(name = "funky")
class MyFunkyEntity(
@Id
var id: String = UUID.randomUUID().toString(),
@Column(name = "title", nullable = false)
var title: String,
@Column(name = "description", nullable = false)
var description: String,
)
// and i have a service that is using the repository
@Service
class MyFunkyService(
private val myFunkyRepository: MyFunkyRepository,
) {
fun funkyAmount() = myFunkyRepository.count()
fun addFunkiness(f: MyFunkyEntity) = myFunkyRepository.save(f)
}
// now i would like to write a little internal DSL to add entries to the repository by using the service
@DslMarker
annotation class MyFunkyDsl
@MyFunkyDsl
fun <T> addFunkyStuff(init: MyFunkyEntity.() -> T): T {
// TODO: somehow inject MyFunkyService and store fields set by init callback
}
// so i could just use 'addFunkyStuff' lambda anywhere in my code like this:
class UseDslExample {
fun someFunction() {
addFunkyStuff {
title = "xyz"
description = "abcd"
}
}
}
is this possible in any way or what could be an alternative approach to write an DSL for a use-case like that?thana
12/28/2020, 12:12 PMstatic
Christian Dräger
12/28/2020, 3:58 PMmarzelwidmer
12/28/2020, 4:12 PMmarzelwidmer
12/28/2020, 4:13 PM// Kotlin DSL
countries(
country {
name = "Switzerland"
capital = "Bern"
population = 8_603_900
currency = "CHF"
},
country {
name = "Spain"
capital = "Madrid"
population = 47_100_396
currency = "EUR"
}
)
marzelwidmer
12/28/2020, 4:14 PMFluxToSOAP
https://github.com/marzelwidmer/kboot-flux-meets-soap/blob/master/soap-server/src/main/kotlin/ch/keepcalm/demo/ws/SoapServer.ktChristian Dräger
12/28/2020, 4:19 PM