Skip to content

Constructor with parameters for ValidationError and ValidationError.Create #149

Description

@jeangatto

Hi! I was thinking of improving the approach by initializing the ValidationError class.

Instead of:

if (await _repository.ExistsAsync(request.Email))
{
    return Result.Invalid(new List<ValidationError>
    {
        new ValidationError
        {
            ErrorMessage = "The email address provided is already in use"
        }
    });
}

To do this:

if (await _repository.ExistsAsync(request.Email))
{
    return Result.Invalid(ValidationError.Create(new ValidationError(""));
}

public class ValidationError
{
    public ValidationError(string errorMessage)
    {
        ErrorMessage = errorMessage;
    }

    public ValidationError(string identifier, string errorMessage, string errorCode, ValidationSeverity severity)
    {
        Identifier = identifier;
        ErrorMessage = errorMessage;
        ErrorCode = errorCode;
        Severity = severity;
    }

    public ValidationError()
    {
    }

    public string Identifier { get; set; }

    public string ErrorMessage { get; set; }

    public string ErrorCode { get; set; }

    public ValidationSeverity Severity { get; set; }

    public static IList<ValidationError> Create(params ValidationError[] errors) => new List<ValidationError>(errors);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions