Closed bartoszlenar closed 2 years ago
If you do decide to go ahead with this, here's some things I've learned from doing this in FV:
WithMessage(tokens => $"The value {tokens.Value} is not equal to 666")
, which is tokenized at compile-time rather than at runtime (with hindsight, I wish I only supported this option in FV, and not the runtime placeholders, but string interpolation didn't exist when FV was started!) @JeremySkinner, I'm still wondering whether I should prioritize this one high. It looks like a great feature, but how often in real life users insert full content of the validated value into the error message?
I see several potential risks here:
One thing that makes it a tough decision for me is that Validot's performance comes from the aggressive caching strategy. All error messages (in all languages, all the paths, etc.) are prepared upfront and delivered to the end report based on the validation logic. Inserting validated values into the error messages means creating them during each validation process. Thus, it instantly kills the main selling point that Validot has - being fast and memory efficient.
Also, relying so massively on caching makes the WithMessage(tokens => $"The value {tokens.Value} is not equal to 666")
virtually impossible, as WithMessage
evaluation and message constructing takes place during Validator initialization, before any real validation. It needs to be another layer or some trick that I need to came up with.
I'm torn apart really when it comes to this idea. I think I'll postpone it till I have a more extensive user base, and people start upvoting this thread.
FYI @JeremySkinner ultimately, I'm closing this down. The reasons as basically here in this thread for 2 years now. So far I haven't found justification for messing up so badly with the performance.
The only way I see it possible is at the very end, maybe in a form of a helper method to IValidationResult
that would somehow correlate the value, the path and the message. Something more like this
User.Name ("elizabeth"): Must start with a capital letter
Where elizabeth
is extracted from model and injected into the final printing.
But that's another story, nor another ticket. This one I'm closing down.
Feature description
Feature in action
Feature details
{_model}
placeholder would be in the cache and replaced with the actual value just during the validition.Questions
That's technically, possible, but why implement this? Is this really needed?
The fact that it's possible doesn't mean it's easy. And would certainly affect the perfromance.