Validation Application Block and .NET 4.0 Code Contracts

Has anyone implemented the Enterprise Library VAB along wtih Code Contracts in .NET 4.0?

If so, can you share some insights? Did it help in performance? Any other factors to be considered?

Answers


Both frameworks have a different scope so they could easily be used in the same project. However, you'll have to prevent using Code Contracts in your domain entities. When you do this, all callers must ensure that they don't set invalid values (a compile time error will occur when you do this). With Validation Application Block however, your entities must be allowed to have an (temporarily) invalid state. Otherwise VAB is unable to ever detect invalid objects.

Let me put it otherwise, Code Contracts is meant to prevent programming errors, not user errors and it gives compile time support for this. VAB prevents user errors, not programming errors* and gives runtime support for this.

*Okay, VAB could also be used for programming errors (and in fact, I do use it myself in this way) but main scenario is user input IMO.


Need Your Help

Polymer 1.0 custom element in leaflet-map not working

javascript polymer leaflet web-component

can anybody explain why the following 2 snippets do not have the same effect / what am I doing wrong at the 2nd :

Error when adding jpa repositories to spring

java spring hibernate jpa

I try to use spring repositories in my project but when i try to configure like this http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.create-instances.spring