C#C
C#2y ago
13 replies
ZML

Data validation

Hello, I have a question regarding data validation. I'm working on a project in ASP.NET Core WebApi. My project consists of 3 layers: Core, Infrastructure, and WebApi. I'm using the Repository pattern. I'm wondering in which layer to perform data validation. Let's take the example of user account registration. Data such as email, password (with password validation handled in the PasswordService), first name, last name, etc., are passed to the API. Should I validate this data in the Core layer when creating the Customer object (e.g., in the constructor using methods like SetName, SetEmail, etc.), or should I create a class responsible for data validation in the WebApi layer? Thank you in advance for your help
Was this page helpful?