protected override async Task Handle(CreateRoomServiceRequest request, CancellationToken cancellationToken) { var room = await _roomRepository.GetById(request.RoomId); if (room == null) { throw new RoomNotFoundException($"RoomId {request.RoomId.ToString()} does not exist."); } var employee = await _employeeRepository.GetById(request.EmployeeId); if (employee == null) { throw new EmployeeNotFoundException($"Employee {request.EmployeeId.ToString()} does not exist."); } var roomService = RoomService.CreateFor(RoomId.CreateFor(request.RoomId), EmployeeId.CreateFor(request.EmployeeId)); await eventStore.Save <RoomService, RoomServiceId>(roomService); //We send the integration events after transaction is ok. foreach (var @event in roomService.GetChanges()) { await _mediator.Publish(@event); } }