My current requirements are overriding validation at runtime when validating a models state after posting a form.
I have a working solution of using normal Data Annotations for model state validation, that's standard in the world of .net, but what I would like to do is, override that validation at runtime.
I know is possible using Microsoft.Practices.EnterpriseLibrary, here is an example of an stack exchange question on the topic, Runtime Model Validation, ideally I'd like the kind of behavior to change model validation at runtime, instead of Re-deploying the solution and doing the necessary changes on the model class.
Ideally I'd like this kind of behavior without having to use Microsoft.Practices.EnterpriseLibrary since its been deprecated a couple years back.
The test program I'm currently working in is a .net 6 controller/view project.
Any suggestions relating to .net 6 would be helpful, I've looked in fluentValidation for this, currently not a support feature atm.
Thanks guys.
I found a solution to reading runtime parameters from a config file:
First, you need to store whatever parameters you need in you config file.
appsettings.json
Then you need to create a custom Validator attribute class:
(you can make this class directly in your ViewModel class if you want)
Notice in the constructor the value gets pulled from appsettings.json, where it is then stored until validation occurs.
The last step is giving the attribute to the field you want:
Since, the constructor doesn't have any required parameters you don't need to pass anything to the validator, but you can change the field name displayed in the error messages
This will validate required, minimum length, and matching a regular expression (which I used to determine if the password has special characters and upper/lower case)