views:

169

answers:

1

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?

+1  A: 

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.

Steven
Code Contracts does both compile-time and runtime checking (depending on which version of Visual Studio you are using).
adrianbanks
I didn't actually say that CC didn't give runtime support :-) The main point is that it checks against programming errors.
Steven
@Steven - Thanks for the concise answer. How do you use VAB for preventing programming errors?
@user102533: When you have a process that runs automatically without any user input, you still want to validate all entities before sending them to the database. But when entities are considered invalid, the cause is a programming error, not invalid user input. Still, the process over validating those entities is exactly the same.
Steven