Cover

Niagara's Validation DSL - First Pass

September 28, 2009
No Comments.

Url: http://niagara.codeplex.com

While Niagara is not going to require that you specify your validation attributes using its DSL, there are some benefits I think we can get by loosely coupling the validation. To that end, i’ve come up with a very first draft of the DSL to define the attributes. I’ve decided that instead of being very English-like, to mimic the “M” style of language.  Here is my take:

// Niagara.Sample.Validation.validation
ValidationInfo
{
  Validators
  {
    // Some validators are built in
    // E.g. the System.ComponentModel.DataAnnotations
    MyCustomValidator = 
      "MyCustomValidator, Niagara.Example.Validators, Version 0.1"
  }
  
  Types("XBoxGames.Data, Version=1.0.0.0")
  {
    XBoxGames.Data.Game
    {
      Name { Required, StringLength(100) },
      Price { Range(0,2000) },
      Rating 
      {
        Required,
        MyCustomValidator("Adult", 1000)
      }
    },
    XBoxGames.Data.Genre
    {
      Name
      {
        Required,
        StringLength(100)
      }
    },
    XBoxGames.Data.Rating
    {
      Name
      {
        Required,
        StringLength(100)
      }
    }
  }
}

For any comments, please add them to the codeplex site here instead of commenting on the blog:

http://niagara.codeplex.com/Thread/View.aspx?ThreadId=70371