Reputation: 1399
In my application i use this structure:
Controller -> Services -> Repositories
I create repositories + filters as dal layer. But i place validation methods (for required fields for example) in service layer. Is this correct? Or better will be if i replace validation in repository layer?
And second question. In this architecture services can operate with many repositories. Will be a good to allow services operate with other services or only i need to operate with repositories ?
Upvotes: 0
Views: 172
Reputation: 12854
There are a couple of libraries out there that can help you with validation.
The first (which I personally use) is FluentValidation that allows you to create validators for your model objects. It can be found at http://www.codeplex.com/FluentValidation
There's another library out there specifically for ASP.NET MVC applications that provides both server-side and client-side validation called xVal. http://www.codeplex.com/FluentValidation
I usually setup my projects the way you have mentioned and most of my logic and/or validation happens in the service layer and the repository layer is simply for queries.
Upvotes: 1
Reputation: 11564
There's a very good tutorial on validation within MVC here...
You should take a look.
Upvotes: 1