validation-spec
validation-spec copied to clipboard
Enforce constraint validators to support injection if CDI is available
I thought this was actually enforced in the spec since a long time, but it turns out it's not:
If CDI is supported in the container, it would be a benefit for developers if they could rely that an implementation also supports dependency injection in the validator.
https://beanvalidation.org/2.0/spec/#integration-dependencyinjection enforces this only that the validator must be injectable itself, but not "inside". Additionally the scope then should be handled by CDI, if a CDI scoped annotation is present.
Example
@ApplicationScoped
public class OrderValidator implements ConstraintValidator<ValidOrder, CoffeeOrder> {
@Inject
CoffeeShop coffeeShop;
// ...
Most impls IMO do this already, but it turns out not all (e.g. Payara), since it's not enforced in the spec. WDYT?
It would probably make sense.
What's unclear to me is why Payara wouldn't support it given they are using Hibernate Validator IIRC and Hibernate Validator supports it.