[bv-dev] Tightly coupled validation

Gunnar Morling gunnar at hibernate.org
Sun May 27 06:44:33 EDT 2012


Hi,

If I understand you correctly, your question is related to the cyclic
dependency between constraint annotations and constraint validators.

As of BV 1.0 I don't see another way than using an XML constraint
mapping as already suggested by Matt and Hardy.

There was a discussion on the subject within the EG a while ago [1],
but we didn't really come to a conclusion back then. One idea was to
employ the service loader mechanism to contribute validator
implementations [2]. I still think that's quite promising.

--Gunnar

[1] http://lists.jboss.org/pipermail/beanvalidation-dev/2011-October/000064.html
[2] http://lists.jboss.org/pipermail/beanvalidation-dev/2011-October/000075.html



2012/5/25 Cemo <cemalettin.koc at gmail.com>:
> Hi,
>
> I am not sure is this already discussed or not but currently I believe that
> validation spec is very strict about coupling.
>
> For example at interface level validator is declared by Interface.
>
> @Constraint(validatedBy = EmailValidator.class)
> @Retention(RUNTIME)
> public @interface Email
>
>
> And for the part EmailValidation part, we are referring again our Email
> Interface
>
> public class EmailValidator implements ConstraintValidator<Email, String>
>
> What I think is this contract is little tight. And because of the strict
> contract, splitting validation by its interface is not possible.
>
> And let me to clarify my use case too.
>
> I have splitted my domain, validation and web projects (Web1, Web2, Web3)
> and using spring extensively.
>
> Domain (Has no dependency)
> Validation (Has dependency to validation spec and optionally Spring
> Framework. For example, It can validate an uniqueEmail field by checking
> database. )
> Web's (Has dependency to validation and domain)
>
> My domain needs dependency to validation for validating it but it means also
> depending spring and all other stuffs regarding Database validations. What I
> want to split Validation contract to interfaces and implementations.
> Interfaces could be declared at domain and implementations reside at
> validation module. Validation module has a dependency to domain perfectly.
>
> I have checked builtin constraints implementations but it seems there is not
> any extensible points for it.
>
> What are your suggestions for this situation?
>
> Thanks
>
>
> _______________________________________________
> beanvalidation-dev mailing list
> beanvalidation-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/beanvalidation-dev
>



More information about the beanvalidation-dev mailing list