November 2018
Intermediate to advanced
388 pages
9h 5m
English
CDI producers comes with the @Produces annotation. It is useful when we need to have complete control over the instantiation of the bean, with some custom code execution, before actually creating the instance.
Let's write an IdentityCreator class. It has a function called createPerson(), which takes inputData as an argument. If the person has preferred choice of language, it is represented by the preferredLanguage attribute. If preferredLanguage is not given in inputData, we will have to create a person instance with defaultPreferredLanguage. This is shown in the following code:
class IdentityCreator { private lateinit var defaultPreferredLanguage:PreferredLanguage fun createPerson(inputData: InputData): Person { val person = Person() ...
Read now
Unlock full access