Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Validation Behavior Pipeline #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thanhbao0408
Copy link

@thanhbao0408 thanhbao0408 commented Sep 24, 2022

This enhancement lets you have the flexibility for not ading the IAbstractValidator implementation to every handler message.
Also, it lets you inject services into the constructor of the validator

// You don't need to add a Validator class if the validation logic is empty
    public class CreateCustomer
    {
        public record Command : ICreateCommand<Command.CreateCustomerModel, CustomerDto>
        {
            public CreateCustomerModel Model { get; init; } = default!;

            public record CreateCustomerModel(string FirstName, string LastName, string Email, Guid CountryId);

            //internal class Validator : AbstractValidator<Command>
            //{
            //    public Validator()
            //    {
            //    }
            //}
        }
    }
// You can inject services here for validating
internal class Validator : AbstractValidator<Command>
{
    public Validator(IRepository<Product> _productRepo)
    {
        // use the repo for checking some database condition
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant