My favorites | Sign in
Logo
                
Show all Featured wiki pages:
Main XmlConfiguration
Blogs:
Feeds:
People details
Project owners:
  dejan.fajfar

Our motto is that validation is not just about the front-end, and we mean it!

We believe that validation deserves more attention than it usually enjoys.

Valy is designed to follow the following software design principles:

The DRY principle is upheld by defining your validation logic in an humanly readable XML format and generate the individual validators from there.

An example validation setup for a person might look like this:

<validators>
  <validator name="UserNameValidator" base_type="System.string">
    <validator ref="StringNullOrEmpty" />
    <validator ref="Regex">
      <regex>^([a-zA-Z0-9]{6,15})$</regex>
    </validator>
  </validator>
  <validator name="PasswordValidator" base_type="System.string">
     <validator ref="StringNullOrEmpty" />
      <validator ref="Regex">
        <regex>^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$</regex>
      </validator>
  </validator>
</validators>

<object type="Foo.Person, Foo">
  <invariants>
    <member name="UserName" type="System.string">
      <validator ref="UserNameValidator" />
    </member>
    <member name="Password" type="System.string">
      <validator ref="PasswordValidator" />
    </member>
  </invariatns>
  <preconditions>
    <property name="UserName" direction="set">
      <validator ref="UserNameValidator" />
    </property>
    <method name="SetPassword">
      <parameter name="password">
        <validator ref="PasswordValidator" />
      </parameter>
    </method>
  </preconditions>
</object>

From this definition Valy will generate classes used to enforce the validation definitions.

namespace Foo
{
  public class Person
  {
    private string userName;
    private string password;
    private IPersonValidator validation;

    public Person(IValidator validation)
    {
      this.validation = validation.For<Person>;
    }

    public string UserName
    {
      get
      {
        return userName;
      }
      set
      {
        if(validation.validateUserName(value))
          userName = value;
      }
    }

    public void SetPassword(string password)
    {
      if(validation.PreconditionFor(o => o.SetPassword, password))
        password = password;
    }
  }
}

It is not the best example in the world but still the power of valy is shown.









Hosted by Google Code