[bv-dev] BVAL-238 Dependency injection in ConstraintViolation
Sebastian Thomschke
sebastian.thomschke at web.de
Fri Oct 21 19:33:54 EDT 2011
Hi Emmanuel,
the proposal talks about a ConstraintViolationFactory. I guess you meant
ConstraintValidatorFactory?
In OVal dependency injection works like this: OVal instantiates the
validator (check) object itself and then passes it to an optional
CheckInitializationListener which can wire required dependencies. So the
DI system does not create the validator instances but configures the
dependencies.
For Spring DI in OVal you do:
ClassPathXmlApplicationContext ctx = new
ClassPathXmlApplicationContext("SpringInjectorTest.xml",
SpringInjectorTest.class);
AnnotationsConfigurer myConfigurer = new AnnotationsConfigurer();
myConfigurer.addCheckInitializationListener(new
BeanInjectingCheckInitializationListener());
Validator v = new Validator(myConfigurer);
Where the BeanInjectingCheckInitializationListener is implemented like:
public class BeanInjectingCheckInitializationListener implements
CheckInitializationListener {
public void onCheckInitialized(final Check newCheck) {
// wire the dependencies
SpringInjector.get().inject(newCheck);
}
}
For Bean Validation this could look like:
|ValidatorFactory factory = Validation
.byDefaultProvider()
.configure()
.addValidatiorInitializationListener(new SpringBeanInjectingValidatorInitializationListener())
.buildValidatorFactory();
Regards,
Seb
|
On 21.10.2011 23:55, Emmanuel Bernard wrote:
> Hi team,
> I've been thinking about BVAL-238 and came up with a first round of ideas and open questions.
> It is available here http://beanvalidation.org/proposals/BVAL-238/
>
> Please give me your feedback. I think this issue can be closed quite quickly.
>
> I've also created a proposals section on the website that will contain such work in progress proposals before inclusion in the spec proper. Check out http://beanvalidation.org/proposals
>
> On a side note, for casual website editing, you can use GitHub's `Edit this file` button (see https://github.com/beanvalidation/beanvalidation.org/blob/master/proposals/BVAL-238.md ). It's not quite a wiki but that's pretty close. One thing you cannot do is create a new file unfortunately. Anyone that have asked for write access should see this button.
>
> Emmanuel
> _______________________________________________
> beanvalidation-dev mailing list
> beanvalidation-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/beanvalidation-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/beanvalidation-dev/attachments/20111022/018c377d/attachment.html
More information about the beanvalidation-dev
mailing list