The @Inject annotation for a service, defined by "@ApplicationScope" fails to inject in Kotlin.
"kotlin.UninitializedPropertyAccessException: lateinit property greeter has not been initialized"
The explanation on similar question: "This problem results as a combination of how Kotlin handles annotations and the lack of the a @Target on the ... annotation definition. Add @field: xxx"
Question is, how do I make this work for a service injection?
import com.amazonaws.services.lambda.runtime.Context
import com.amazonaws.services.lambda.runtime.RequestHandler
import javax.enterprise.context.ApplicationScoped
import javax.inject.Inject
class HelloRequest() {
var firstName: String? = null
var lastName: String? = null
}
@ApplicationScoped
open class HelloGreeter() {
open fun greet(firstName: String?, lastName: String?): String {
return "$firstName, $lastName"
}
}
class HelloLambda : RequestHandler<HelloRequest, String> {
@Inject
lateinit var greeter: HelloGreeter
override fun handleRequest(request: HelloRequest, context: Context): String {
return greeter.greet(request.firstName, request.lastName)
}
}
Similar questions: "This problem results as a combination of how Kotlin handles annotations and the lack of the a @Target on the ... annotation definition. Add @field: xxx"