Add BAEL-2067 DomainEvents examples
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.ddd.event;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DomainService {
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
private final AggregateRepository repository;
|
||||
|
||||
public DomainService(AggregateRepository repository, ApplicationEventPublisher eventPublisher) {
|
||||
this.repository = repository;
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void serviceDomainOperation(long entityId) {
|
||||
repository.findById(entityId)
|
||||
.ifPresent(entity -> {
|
||||
entity.domainOperation();
|
||||
repository.save(entity);
|
||||
eventPublisher.publishEvent(new DomainEvent());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user