我正在使用 FluentValidation 框架。目前我有几个验证器(每个实体)。我将实体保存在单独的程序集 (ProjectName.Domain
) 和验证器中。
我读过有关在存储库和控制器之间呈现中介层的服务层(http://www.asp.net/mvc/tutorials/older-versions/models-(data)/validating-with-a-service-layer-cs)。
可以将服务层
放在同一个程序集中吗?
据我了解,服务层的目的是保存具体(或可能通用)存储库和相应的验证器,并对存储库项进行验证。因此,实现可能会有所不同。我说得对吗?
如何使服务层以正确的方式使用 FluentValidation(或独立于框架)。或者将基本实体与一些 FluentValidation AbstractValidator 类集成是否可以接受。
谢谢!
I'm using FluentValidation
framework. And at the moment I have several validators (per entity). I'm keeping entities in a separate assembly (ProjectName.Domain
) and validators either.
I've read about a service layer that presents mediator layer between repositories and controllers (http://www.asp.net/mvc/tutorials/older-versions/models-(data)/validating-with-a-service-layer-cs).
Is it OK to hold service layer
in the same assembly?
As far as I understand the purpose of service layer is to hold concrete (or possibly generic) repository and corresponding validator and make a validation over repository items. So implementations may vary. Am I right?
How to make service layer using FluentValidation (or framework independent) the right way. Or would it be acceptable to integrate base entity with some FluentValidation AbstractValidator class
.
Thanks!
发布评论
评论(1)
分离层不需要物理上分离的组件。事实上,您拥有的程序集越多,管理解决方案就越困难/麻烦。分层是一个合乎逻辑的问题。也许它是由命名空间或命名约定分隔的。
据我了解,服务层的目的是保存具体(或可能通用)存储库和相应的验证器,并对存储库项进行验证。因此,实现可能会有所不同。我对吗?
这可以是服务层的一种用途,但不一定如此。 “服务”一词在过去几年中已经被过度使用,以至于几乎没有任何意义。
对应用程序进行分层的目的是让应用程序能够适应变化。这是一个非常模糊的说法,但这就是它的目的。层允许封装,封装允许更改。
separating layers doesn't require physically separate assemblies. in fact the more assemblies you have, the more difficult/cumbersome it is to manage a solution. separating layers is a logical concern. maybe it's separated by namespace, or a naming convention.
As far as I understand the purpose of service layer is to hold concrete (or possibly generic) repository and corresponding validator and make a validation over repository items. So implementations may vary. Am I right?
that can be one use for a service layer, but it doesn't have to be. The term "services" has has become overused in the last few years to the point that it almost means nothing.
the purpose of layering your application is to allow the application to adapt to change. that's a very vague statement, but that's all it's designed to do. layers allow encapsulation and encapsulation allows for change.