Scopes

CDI has a number of scope annotations. Every managed bean either explicitly or implicitly defines the scope, and the scope specifies the life cycle of all the instances of the beans. For example, we have an EJB session bean of an application with a stateless scope, as shown in the following code:

@Statelessclass App {    @Inject    private lateinit var identityCreator: IdentityCreator    @Inject    private lateinit var identityRepository: IdentityRepository    fun createIdentity(inputData: InputData): Identity {        val person = identityCreator.createPerson(inputData)        identityRepository.store(person)        return person    }}

Stateless beans are pooled by the application server. We have several instances of the bean, which is the concern of the application server. ...

Get Kotlin for Enterprise Applications using Java EE now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.