进行验证的地方 [英] Place for validation

查看:120
本文介绍了进行验证的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序使用此结构:

控制器 - >服务 - >库

创建库+过滤器为DAL层。但是我把验证方法(例如必填项)在服务层。它是否正确?或者更好的将是,如果我在库层更换验证?

和第二个问题。在这种架构中的服务可以与许多资源库运行。将是一个很好的让服务与其他服务运营或只有我需要仓库操作?


解决方案

有几个库在那里,可以帮助您与验证。

第(我个人使用)是FluentValidation,允许你创建你的模型对象的验证。 //www.$c$cplex.com/FluentValidation <:它可以在 HTTP找到/ p>

有对提供所谓的XVAL了服务器端和客户端验证ASP.NET MVC应用程序的另一个库在那里特别。 HTTP://www.$c$cplex.com/FluentValidation

我通常设置我的项目你所提到的,大部分我的逻辑和/或验证的发生在服务层和库层简单的查询。顺便

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 ?

解决方案

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.

这篇关于进行验证的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆