Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use event interface in entity class #2019

Open
sergeevik opened this issue Mar 19, 2025 · 0 comments
Open

Use event interface in entity class #2019

sergeevik opened this issue Mar 19, 2025 · 0 comments
Labels
type: enhancement A general enhancement

Comments

@sergeevik
Copy link

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);
	}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 19, 2025
@schauder schauder added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants