Let's create a custom annotation, such as Auditable, to audit a business function in an application:
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Documented
annotation class Auditable
The Auditable annotation is itself annotated with @InterceptorBinding and has a runtime retention policy to make the annotation visible at runtime.
We can use Auditable in business functions as follows:
@Stateless
class App {
@Inject
private lateinit var identityCreator: IdentityCreator
@Inject
private lateinit var identityRepository: IdentityRepository
@Auditable
fun createIdentity(inputData: InputData): Identity {
val person = identityCreator.createPerson(inputData)
identityRepository.store(person)
return person
}
}