Niagara's Validation DSL - First Pass


Url: http://niagara.codeplex.com

Project Niagara

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



Shawn
Shawn Wildermuth
Author, Teacher, and Coach



My Courses

pluralsight
Building a Web App with ASP.NET Core, MVC6, EF Core, Bootstrap and Angular (updated for 2.0)
Using Visual Studio Code for ASP.NET Core Projects (new)
Implementing and Securing an API with ASP.NET Core
Building a Web App with ASP.NET Core, MVC6, EF Core and AngularJS
Building a Web App with ASP.NET5, MVC6, EF7, and AngularJS (Retired)
Best Practices in ASP.NET: Entities, Validation, and View Models
Webstorm Fundamentals
Front-End Web Development Quick Start
Lessons from Real World .NET Code Reviews
Node.js for .NET Developers

Application Name WilderBlog Environment Name Production
Application Ver 2.0.0.0 Runtime Framework .NETCoreApp,Version=v2.0
App Path D:\home\site\wwwroot\ Runtime Version .NET Core 4.6.26020.03
Operating System Microsoft Windows 10.0.14393 Runtime Arch X86