Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Best/Recommended way to include a ruleset as a subset of another ruleset?

$
0
0
Hi all,

I am currently using Fluentvalidation to validate some ViewModels on our site.

On an insert, certain properties are required, and on an update, those certain properties are still required, with the addition of the ID property of the model in question.
        RuleSet("InsertRules", () =>
        {
            RuleFor(x => x.DoctorLastName)
                .NotEmpty().WithMessage("Last Name must be supplied.");

        });

        RuleSet("UpdateRules", () =>
        {
            RuleFor(x => x.DoctorID)
                .NotEmpty().WithMessage("DoctorID must be supplied.")
                .GreaterThan(0).WithMessage("Invalid DoctorID.");

        });
Is there a way that I could allow my code to specify only the UpdateRules ruleset, and know that the InsertRules ruleset would be triggered as well? Thinking this would be cleaner than specifying "*" in our case , and would make the calling code more explicit as to what it was trying to do.

Appreciate any thoughts on this. Thanks!

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>