views:

76

answers:

2

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?

+1  A: 

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
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
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
Cool, looks that i will try to use this VAB. Aslo i have performed some test for 1000 validations ... so far looks good.
user3072
A: 

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
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
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
Yes it could be possable solution :)
user3072