Data validation in Repository Pattern RRS feed

  • Question

  • User1801900496 posted

    hey all

    I am currently using the 3-tier Repository pattern in my application. Actually it's the first time for me to implement a design pattern at all! i used to put all my code in the so called now presentation layer.

    Since i am new to the subject, i need help on the following: if i want to implement data validation, for example, password should not be more than 10 characters and have to contain special characters. Should i put this code in the data access layer? but my data access layer contains methods that take the DTO as a parameter for example

    public void add (DataObject Obj)
       //code to call the stored procedure and insert the data contained in obj

    and the same is for other CRUD operations (DELETE and UPDATE), so implementing such validation on the DAL would make me duplicate the code in each and every method that accepts the DataObject as a paramter. Same holds for the business logic layer where i am using it as a proxy between the presentation and the data access layers. Eventually it has to use the same Data Objects as parameters. This only leaves me with one option which is to do the validation on the Data Object part. But i think this is not the essence of the respository pattern which states that the Data object class should only be a "container" class with no behavior.

    Finally, i would really appreciate if anyone pointed me to a book on Repository Design Pattern in C#. Thanks a lot in advance

    Tuesday, December 21, 2010 1:57 PM