Where do you do your validation/business rules?
I'm making a ASP.NET MVC application using EF4, using the Controller --> View Model --> Service Layer --> Repository --> Data Model (EF) approach.
My question is where does the business logic/validation live at?
Should I be making copies of the domain objects into view objects and validating there? Seems like a lo开发者_JAVA百科t of extra work to duplicate the domain objects into objects for the view models.
I am using POCO's generated using the T4 templates.
Personally I put business validation logic (things like username is already taken, cannot wire money because of insufficient funds, ...) in the Service Layer and things like the username fields is required on the view model.
I actually like @Darin Dimitrov's method and this is what I'm currently using on my project. And in order to take advantage of displaying error messages just like you would do with using attributes, you can use a wrapper around the ModelState as explained in this article.
精彩评论