After reading this article about validating with service layer I have some doubts.
First: Is it all right to pass the whole model view to the service as shown in article ? I have seen some example where rather then passing whole model that is used by controller (like bool success = _productService.CreateProduct(productModel)
) they called services like this:
bool success = _productService.CreateProduct(productModel.Name, productModel.Category, productModel.Cost)
What are pros/cons of both approaches ?
Second: I can see the logic in using same service for validating model and doing the actual work. On the other hand it means that the service will have to deal with 2 concerns: data validation and data processing. That means more code in the same service and worse testability, right ?
So instead of example code above would it be better to have:
bool valid = _productValidationService(productModel);
if(valid){
_productService.CreateProduct(productModel);
//or maybe _productService.CreateProduct(productModel.Name, productModel.Category, productModel.Cost);
}
What are the pros/cons ? Is there something that I don't see ? What do you use ? What is standard approach ?