Open
Description
The current event model requests the creation of a bean component to implement the child AbstractRelationalEvent (AfterSaveEvent / BeforeConvertEvent / ...)
If the event logic is strongly related to the entity, then now you have to divide them into classes, perhaps make some private attributes public.
You can add processing logic if the entity itself implements these interfaces. Do not publish the event (or with publish), but call the method on the entity
If the event model will check the implementation of the interface and call it instead of or together with sending the event, then it will be possible to combine the entity and its reaction to events in one class
for example something like this:
package org.springframework.data.jdbc.core;
...
public class JdbcAggregateTemplate implements JdbcAggregateOperations {
...
private <T> T triggerBeforeConvert(T aggregateRoot) {
if (aggregateRoot instanceof BeforeConvertCallback) {
return ((BeforeConvertCallback<T>) aggregateRoot).onBeforeConvert(aggregateRoot);
}
eventDelegate.publishEvent(() -> new BeforeConvertEvent<>(aggregateRoot));
return entityCallbacks.callback(BeforeConvertCallback.class, aggregateRoot);
}