I'm new to FluentValidation, so please bear with me if I'm being an idiot.
I'm looking at using MVC4 with FluentValidation to provide validation rather than using design-time attributes which don't fit well in my design.
What I'm trying to do is provide runtime validation based on database fields.
For example, I'll read a number of records from the database which represent a series of questions for which I want the user to enter answers.
Each question and answer is in a QAs collection within a "questionset" model.
Each QA can be of a different type (eg Q1 could be a date, Q2 could be an integer, Q3 could be a selection from a list). The type is part of the model and is handled in the view through templates, which works fine.
What I now want to do is apply different validation to each occurrence of QA within the collection....Q1 needs to be a date in the past, Q2 needs to be a value from 1-100. Q3 needs to be a valid selection from the list......All of the information about the type of validation is available in my QA model.....
What I think I want to do is create RuleFor's within the model's Validate method, based on the current instance of the QA.....But I figure this is actually too late in the process? I can't create them in the constructor, because I don't know what type to create - I can't access the instance there?
Can anyone point me in the right direction?
I'm looking at using MVC4 with FluentValidation to provide validation rather than using design-time attributes which don't fit well in my design.
What I'm trying to do is provide runtime validation based on database fields.
For example, I'll read a number of records from the database which represent a series of questions for which I want the user to enter answers.
Each question and answer is in a QAs collection within a "questionset" model.
Each QA can be of a different type (eg Q1 could be a date, Q2 could be an integer, Q3 could be a selection from a list). The type is part of the model and is handled in the view through templates, which works fine.
What I now want to do is apply different validation to each occurrence of QA within the collection....Q1 needs to be a date in the past, Q2 needs to be a value from 1-100. Q3 needs to be a valid selection from the list......All of the information about the type of validation is available in my QA model.....
What I think I want to do is create RuleFor's within the model's Validate method, based on the current instance of the QA.....But I figure this is actually too late in the process? I can't create them in the constructor, because I don't know what type to create - I can't access the instance there?
Can anyone point me in the right direction?