Thanks Allard,
Downloading Axon 2.3 dependencies as we speak. Some great new features it seems, thank you.
My aggregate root constructor is as follows, I want to throw validation exceptions to ensure business invariants within the aggregate.
I believe Axon 2.3 GatewayProxyFactory's CommandCallBack might be what I am looking for? My aim is to pipe these validation messages to a message queue/websocket.
Alternatively I thought of maybe throwing a validation event but this seems to leak the ensuring of business invariants into event handlers(I'd like to keep them within Aggregate Roots).
Your thoughts are greatly appreciated!
@CommandHandler
public UserAggregateRoot(RegisterUserCommand registerUserCommand, UserRepository userRepository) {
User userWithEmail = userRepository.userWithEmailAddress(new EmailAddress(registerUserCommand.getEmailAddress()));
if (userWithEmail != null) {
//apply(new UserEmailUnavailableEvent(userId.id()));
// throw new ValidationNotificationException(new ValidationException("email", "Email is unavailable"));
}
apply(new UserRegisteredEvent(new UserId(userRepository.newUserId().id(), registerUserCommand.getUsername(), registerUserCommand.getEmailAddress(),registerUserCommand.getPassword(), registerUserCommand.getFirstname(), registerUserCommand.getSurname()));