Skip to content

Enhance Validation Behavior Pipeline#29

Open
thanhbao0408 wants to merge 1 commit into
thangchung:mainfrom
thanhbao0408:enhance-validator-pipeline
Open

Enhance Validation Behavior Pipeline#29
thanhbao0408 wants to merge 1 commit into
thangchung:mainfrom
thanhbao0408:enhance-validator-pipeline

Conversation

@thanhbao0408
Copy link
Copy Markdown

@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
    }
}

Copy link
Copy Markdown

@iamteamstar iamteamstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are only listing data asynchronously, use IQuaryable instead of IEnumarable

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.

2 participants