public async Task HandleAsync(AccountDeletedIntegrationEvent integrationEvent, CancellationToken cancellationToken = default) { try { var user = await _userRepository.GetByIdAsync(integrationEvent.AccountId); user.AddDeletedEvent(integrationEvent.CorrelationId); await _communicationBus.DispatchDomainEventsAsync(user, cancellationToken); await _userRepository.DeleteAsync(user); var userDeletedIntegrationEvent = new UserDeletedIntegrationEvent(integrationEvent.CorrelationId, user.Id); await _integrationEventBus.PublishIntegrationEventAsync(userDeletedIntegrationEvent); } catch (Exception e) { _logger.LogIntegrationEventError(ServiceComponentEnumeration.RivaUsers, integrationEvent, "userId={userId}, message={message}, stackTrace={stackTrace}", integrationEvent.AccountId, e.Message, e.StackTrace); var userDeletionCompletedIntegrationEventFailure = new UserDeletionCompletedIntegrationEventFailure( integrationEvent.CorrelationId, IntegrationEventErrorCodeEnumeration.UnexpectedError.DisplayName, IntegrationEventErrorMessage.UnexpectedError, integrationEvent.AccountId); await _integrationEventBus.PublishIntegrationEventAsync(userDeletionCompletedIntegrationEventFailure); } }
protected void When(UserDeletedIntegrationEvent @event) { Id = @event.AggregateRootId; }
public void Delete(string email) { Raise(UserDeletedIntegrationEvent.Create(this)); }