<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">The point of Hardy (and Gunnar) is that in a DI environment, the Validator(Factory) lifecycle would most likely be handled by the DI framework and thus that the DI could provide proper injected instance to the BV bootstrap. I have to admit I had not completely seen it that way.<div><br></div><div>The BV spec / RI could provide the portable CDI @Provider that implements this logic. For other DIs, they will need to be responsible for it.</div><div><br></div><div>We will see how that plays but in a few ways it requires the DI environment to be aware of the content of validation.xml, we need to prototype that to see if that works well.</div><div><br><div><div>On 4 janv. 2012, at 11:13, Gerhard Petracek wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">hi hardy,<div><br></div><div>you won't get dependency injection support with manual bootstrapping (btw. you would have to use the class of a &gt;concrete&lt; cdi implementation - and that isn't portable).</div><div>

with the service-loader approach a new method for&nbsp;ValidatorContext is also optional.</div><div><br></div><div>regards,</div><div>gerhard</div><div><br></div><div><br><br><div class="gmail_quote">2012/1/4 Hardy Ferentschik <span dir="ltr">&lt;<a href="mailto:hardy@hibernate.org">hardy@hibernate.org</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I prefer option 3 for its simplicity and the fact that it does not change the current bootstrap API.<br>
As you already say, &nbsp;integration is completely managed by the CDI-side in which case I don't see why it<br>
CDI could not manage MessageInterpolator and TraversableResolver as well.<br>
<br>
I also think that Gunnar has a point that introducing InstanceProvider creates some confusion with<br>
the existing API. I also agree that CDI should know about BV, but not the other way around.<br>
<span class="HOEnZb"><font color="#888888"><br>
--Hardy<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On Jan 3, 2012, at 8:25 PM, Emmanuel Bernard wrote:<br>
&gt; #### Option 1: Add a Method to inject the BeanManager instance on Bean Validation bootstrap sequence<br>
&gt;<br>
&gt; One approach would be to let the container set a `BeanManager` instance<br>
&gt;<br>
&gt; &nbsp; &nbsp;ValidatorFactory factory = Validation<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.byDefaultProvider()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.configure()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.cdiBeanManager(beanManager)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; .buildValidatorFactory();<br>
&gt;<br>
&gt; However that would add a hard dependency between CDI and Bean Validation which is probably not welcomed.<br>
&gt;<br>
&gt; An alternative is to use an untyped version (which should probably be favored):<br>
&gt;<br>
&gt;<br>
&gt; &nbsp; &nbsp;ValidatorFactory factory = Validation<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.byDefaultProvider()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.configure()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// T cdiBeanManager(Object beanManager) //raises an exception if that's not a BeanManager<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.cdiBeanManager(beanManager)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; .buildValidatorFactory();<br>
&gt;<br>
&gt;<br>
&gt; vs<br>
&gt;<br>
&gt; &nbsp; &nbsp;ValidatorFactory factory = Validation<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.byDefaultProvider()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.configure()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//raises an exception if that's not a BeanManager<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.addObject(Validation.CDI_BEAN_MANAGER, beanManager) // T addObject(String key, Objet value)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; .buildValidatorFactory();<br>
&gt;<br>
&gt; I however feel chagrined that the nicely typed `Configuration` API requires such untyped approach.<br>
&gt; (I don't think introducing CdiBeanManagerFactory solves any issue, is that true?).<br>
&gt;<br>
&gt;<br>
&gt; - have an untyped version of the above proposal<br>
&gt; - offer a generic `Map&lt;String,Object&gt; addObject(String key, Object value)` method on `Configuration`<br>
&gt;<br>
&gt; #### Option 2: Use CDI facility to retrive the current `BeanManager`<br>
&gt;<br>
&gt; CDI exposes `BeanManager` via JNDI in EE, we could use it.<br>
&gt;<br>
&gt; Also CDI 1.1 offers programmatic lookup via the CDI class, see EDR1 spec for details.<br>
&gt; &lt;<a href="http://docs.jboss.org/cdi/spec/1.1.EDR1/html/spi.html#provider" target="_blank">http://docs.jboss.org/cdi/spec/1.1.EDR1/html/spi.html#provider</a>&gt;<br>
&gt;<br>
&gt; #### Option 3: Ask CDI to inject a CDI aware `ConstraintValidatorFactory` when creating the `ValidatorFactory` object<br>
&gt;<br>
&gt; Another idea would be to integrate BV/CDI via a CDI-aware `ConstraintValidatorFactory` to be provided by CDI runtimes:<br>
&gt;<br>
&gt; &nbsp; &nbsp;ValidatorFactory factory = Validation<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.byDefaultProvider()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.configure()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.constraintValidatorFactory( new CdiAwareConstraintValidatorFactory( beanManager ) )<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.buildValidatorFactory();<br>
&gt;<br>
&gt; That way the integration is completely managed by the CDI-side. `Validator` and `ValidatorFactory` are already<br>
&gt; built-in beans in CDI so this wouldn't add much complexity.<br>
&gt; The CDI runtime would use this factory whenever a `Validator` or `ValidatorFactory` is retrieved.<br>
&gt;<br>
&gt; #### Option 4: Add a method accepting an `InstanceProvider` implementation in Bean Validation's bootstrap<br>
&gt;<br>
&gt; &nbsp; &nbsp;ValidatorFactory factory = Validation<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.byDefaultProvider()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;.configure()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.instanceProvider(cdiInstanceProvider)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; .buildValidatorFactory();<br>
&gt;<br>
&gt; &nbsp; &nbsp;public interface InstanceProvider {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;public &lt;T&gt; T createInstance(Class&lt;T&gt; type);<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;public destroyInstance(Object instance);<br>
&gt; &nbsp; &nbsp;}<br>
&gt;<br>
&gt; The default implementation can be the no-arg constructor we have today. We can either ask CDI to<br>
&gt; provide a `CDIInstanceProvider` at `ValidatorFactory` creation like in option 3 or make it the<br>
&gt; default implementation if CDI is present according to option 2.<br>
&gt;<br>
&gt; This option works fine as long as we don't require more complex object creation logic.<br>
&gt;<br>
<br>
<br>
</div></div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
</div></div></blockquote></div><br></div>
_______________________________________________<br>beanvalidation-dev mailing list<br><a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/beanvalidation-dev<br></blockquote></div><br></div></body></html>