ExpressiveAnnotations icon indicating copy to clipboard operation
ExpressiveAnnotations copied to clipboard

How to decrease the number of registered validation handlers at client-side?

Open senzacionale opened this issue 8 years ago • 1 comments

Can you please make this method protected and virtual

private void AssertAttribsQuantityAllowed(int count)
        {
            const int max = 27;
            if (count > max)
                throw new InvalidOperationException(
                    $"No more than {max} unique attributes of the same type can be applied for a single field or property.");
        }

Url:

https://github.com/jwaliszko/ExpressiveAnnotations/blob/ad078cccc63ca1d83464d55fd913a9dd44999907/src/ExpressiveAnnotations.MvcUnobtrusive/Validators/ExpressiveValidator.cs

Why? I don't want to have max value of 27 but 3. JS is easy to change because is project related.

Regards Mitja

senzacionale avatar Jan 15 '16 19:01 senzacionale

Change to the boundary number, defined in this method, has no sense in current design. At least not without respective changes to the client-side logic (changes which could have effectively decreased the amount of validation adapters registered there).

This method is just a safety guard. Assures, that the number of unique annotations, of the same type, applied to a single field, does not exceed the hardcoded amount. It's because the number of handlers at the client-side, is actually also hardcoded, and limited to this exact amount. Assertion was introduced, because any additional annotation would be deprived of its client-side corresponding handler - so client-validation for such an annotation wouldn't be invoked. It protects users from such a surprise.

I've picked an arbitrary number 27, which is not too high (does anyone need more than 27 unique attributes of the same type applied to a single field?), but not too low as well.

The reasons and the desired solution - to register only as many handlers as needed (not to waste the memory), has been already discussed, in depth, here: https://github.com/jwaliszko/ExpressiveAnnotations/issues/96. This request is definitely not the way to go.

Any pull requests solving this case correctly are very welcome.

jwaliszko avatar Jan 15 '16 20:01 jwaliszko