Hi 2 all!
When I worked on asp.net mvc web site project, I investigated different approaches for validation. Some of them were DataAnotation validation and Validation Block. They use attributes for setting up rules for validation. Like this:
[Required]
public string Name {get;set;}
I was confused how this approach combines with SRP (single responsibilty principle) from OOP world. Also I don't like any business logic in business objects, I prefer "poor business objects" model, but when I decorate my business objects with validation attributes for real requirements, they become ugly (Has a lot of attributes / with localization logic and so on).
Idea with attributes realy simple, but in my opinion the validation decoration should be separated from object. I'm not sure is the approach to separate validation rules to xml files or to another objects, maybe it is a solution.
Another bad side of AOP - problems with unit testin such code. When I decorated some controller actions with custom attributes for example to import/export TempData between actions or initialize some required services I can't to write proper unit test for testing this actions.
Do you think that attributes don't break srp or you just disregard this and think that it's simplest , is not worst way ?
P.S. I read some likes articles and discussions and I just want to put things in proper order.
P.P.S. sorry for my "fluent" english :=)
EDIT I think that 'breaking rules' and ugly will be in such scenario: In case when validation has some business rules - for example users must have unique email in system, you should to validate user input throw all youe layers in app, so when you write your custom attribute to check this data, business object will be connected with your data layer throw attribute.