Project Description
SpecExpress is a fluent validation framework and container for .Net that makes it easier to write validation rules and validate your objects. SpecExpress also offers integration with ASP.NET WebForms, eliminating duplication of your validation rules.

Supported By

ReSharper

Source Code moved to GitHub!

We may explore mirroring it here in the future, but for now consider the Source Code stored here on CodePlex an archive.

SpecExpress is now available to be referenced in your project through NuGet packages.

News and update information can be found at:

http://specexpress.blogspot.com

Features

  • The SpecExpress DSL provides developers with a Fluent Interface for quickly composing rules that are also easy to read. See a Sample
  • Generates error message from your validation rules, but allows for easy overriding and customization of individual messages. Support for localization of error messages.
  • Validation Catalog allows:
    • Auto discovery of specifications means the developer isn't required to resolve which validation rules to use
    • Programatically add or change validation rules at runtime
    • Validation Contexts
  • Support for rich, complex object types and graphs
  • Built with extension and customization in mind
  • Easy to integrate into your existing code because there are no Base Classes or Attributes to inject into your code
  • ASP.NET WebForms support
  • ASP.NET MVC support
  • Silverlight support
  • A rich set of Validators

Approach

SpecExpress takes a different approach than most other Validation Frameworks, such as Validation Application Block. SpecExpress doesn't use Attributes to decorate properties and embed all the metadata required for the rule. Instead, it it uses a separate class, called a Specification, which contains a set a rules for all the properties for a type. This allows for much easier reading, separation of concerns, and much better support for state based validation.

Example

public class AddressSpecification : Validates<Address>
{
    public AddressSpecification()
    {	
        Check(a => a.Street1).Required().And.IsAlpha().And.MaxLength(255);
	Check(a => a.Street2).Optional().And.IsAlpha().And.MaxLength(255);
	Check(a => a.City).Required().And.IsAlpha().And.MaxLength(50);

	Check(a => a.State)
            .If(a => a.Country == "US").Required()
		.And.IsAlpha()
		.And.LengthEqualTo(2);
		.And.IsInSet(StateRepository.GetStates());

	Check(a => a.Country).Optional().And.IsAlpha();

	Check(a => a.ZipCode)
	    .If(a => a.Country == "US").Required()
		.And.LengthEqualTo(5)
		.And.Not.EqualTo("00000");

	Check(a => a.ZipPlusFour)
	   .If(a => a.ZipCode.Any()).Required()
		.And.LengthEqualTo(4)
		.And.IsNumeric();	
    }
}

 

Getting Started

Check out the Quick Start or Developers Guide.

Requirements

SpecExpress requires Microsoft .Net 4.0.

Additional Resources

News

Click here to view the RSS feed.

Contribute

  • Localization of error messages

Last edited Apr 10, 2013 at 6:31 PM by rbell80134, version 53