Friday, November 24, 2006

.Net Validation Framework (Domain Object Validation via Attributes)

CodePlex - .net Validation Framework

"Use .NET attributes to provide validation for your strongly typed business objects.

...

[RequiredStringValidator]
[LengthStringValidator(50)]
public string FirstName...

[RequiredStringValidator]
[RegexValidator("Invalid email format.", @"\w+([-+.]\w+) *@\w+([-.]\w+)*\. \w+([-.]\w+)*")]
[LengthStringValidator(50)]
public string EmailAddress...

[RequiredIntValidator]
[CompareIntValidator(18, ValidationCompareOperator.GreaterThanEqual)]
public int Age..."

Visual Studio Magazine - Validate Business Objects Declaratively

"... I’ll show you how to construct the Declarative Validation framework to validate business objects by decorating class properties with attributes. The framework consists of six built-in validator attributes: RequiredValidator, LengthValidator, RegexValidator, RangeValidator, CompareValidator, and CustomValidator. You can plug the framework into any architecture. It comes with two abstract base classes that you can use to make implementation trivial by querying the IsValid property. ..."

I really like the idea of using attributes to validate my strongly typed domain/business objects...

(via Steve Michelotti - Validation framework on CodePlex)

No comments: