3

Can I use Validation Application Block, for a high performance program? I mean when I'm getting objects from a stream and I need to validate their values as I parse data coming. As I understand reflection is involved...

Is there any alternative tools that i can use for object validation?

Steven
  • 166,672
  • 24
  • 332
  • 435
user3072
  • 65
  • 1
  • 7
  • Define high performance. How many objects are we talking about. Whats are the limits. – Ralf de Kleine Jun 22 '10 at 07:26
  • 1
    Try it. Run a micro-benchmark and see if performance is good enough for your requirements. – Oded Jun 22 '10 at 07:26
  • Lets say 1000 object per second. I'm thinking to work with XML configuration file as Validation rules set. As i sow in source code each Validation reads XML again before executing Validation rules. – user3072 Jun 22 '10 at 09:05
  • Is there any alternative tools that i can use for object validation? – user3072 Jun 22 '10 at 09:07

2 Answers2

1

It will greatly depend on the definition of the objects you validate. Objects that contain many properties that need to be validated or even contain collections of objects that need to be validated, validation takes more time. However, in general, 1000 objects per second would certainly not be a problem for VAB.

Validation Application Block caches the XML configuration file as a object graph in memory, so you don't have to worry about a file load and XML parse each time to validate objects. VAB has some pretty good optimizations.

Steven
  • 166,672
  • 24
  • 332
  • 435
  • Thanks a lot for your answer! This is exactly what i wanted to know, if there any kind of caching mechanism involved. My object are not complicated (they are flat with out collections). Another question - is there any optimization if i'm calling many times Validation for the samy type of object or it making reflection to properties each time? – user3072 Jun 22 '10 at 09:44
  • It is definately using caching to prevent types are being re-reflected each time. The `CreateValidator` method of the `ValidatorFactory` base class, calls the private `FindOrCreateValidator` method. This method first tries to load a validator from the cache, before calling the abstract `InnerCreateValidator` method. – Steven Jun 22 '10 at 11:20
  • Cool, looks that i will try to use this VAB. Aslo i have performed some test for 1000 validations ... so far looks good. – user3072 Jun 22 '10 at 11:44
0

Fluent Validation and Fluent Validation 2.0 are excellent validation frameworks that enable you to validate your classes at any time as well as generate client side validators.

Daniel Dyson
  • 13,192
  • 6
  • 42
  • 73
  • Thanks, i will check those frameworks. From first look they doesn't give the ability to separate validation data from the logic. Talking about XML configuration ability. – user3072 Jun 23 '10 at 06:11
  • True, but there is nothing stopping you from creating your own configuration section and then building your rules on load based on this or from using a dependency injection framework such as Spring.Net to configure the validation. Have a go at Fluent though. I think you will like it. – Daniel Dyson Jun 23 '10 at 08:18
  • Yes it could be possable solution :) – user3072 Jun 27 '10 at 09:12