In my project I use Fluent Validation to define custom validation rules. I have noticed that in many of my validation rules, it is necessary to retrieve a value from a database to perform the validation. The problem is that I am doing the retrieval of data from the database multiple times within the various rules, and this may be impacting performance.
I was wondering if there is a way to perform data retrieval from the database once and use it in all the validation rules, so as to avoid repeated data retrieval.
In searching I found that one possible solution is to initialize the variables in the head but I'm not so sure about that
You could always inject a custom singleton service which could cache and share results between validators.
See: https://docs.fluentvalidation.net/en/latest/di.html