public async Task <User> RegisterUserAsync(string userName, string password) { if (string.IsNullOrWhiteSpace(userName)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(userName)); } if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(password)); } var userExists = await _repository.ExistsAsync(new AccountExistsSpec(AccountType.Internal, userName)) .ConfigureAwait(false); if (userExists) { throw new DomainException(Error.UserNameAlreadyExists, new object[] { userName }); } return(RegisterUser(userName, password)); }