Search code examples
c#asp.netvalidationmvpsolid-principles

how should i validate data


i'm creating a shopping website using asp.net and Model View Presenter pattern and the architecture is layered. i know that i should have validator classes that are responsible for validating user inputs in business layer and i also should have validators in UI layer to follow DEEP and fast user response. so how can i have validator classes in BL to validate data types like int, long and decimal but also follow DRY and SOLID? do i also need abstraction? here are my models:

public class Category
{
    public int Id {get;set;}
    public string Name {get;set;}
    public int? ParentCategory {get;set;}
}
public class Item
{
    public int Id {get;set;}
    public int Category {get;set;}
    public string Model {get;set;}
    public string Color {get;set;}
    public string Brand {get;set;}
    public decimal Price {get;set;}
}

Solution

  • You can use Enterprise library Validation Block its easy and yet loosely coupled. Have a look at the sample tutorial using validation block with ASP.NET MVC but can also easily be used with MVP.

    http://weblogs.asp.net/gunnarpeipman/archive/2009/11/13/asp-net-mvc-validating-objects-using-enterprise-library-validation-application-block.aspx

    Regards.