<div dir="ltr">Hi Jozef,<div><br></div><div>Thank you very much for prompt reply.</div><div><br></div><div>Thanks again.</div><div><br></div><div>Regards,</div><div>Muhammad Bhutto</div></div><div class="gmail_extra"><br><br>
<div class="gmail_quote">On Tue, Nov 19, 2013 at 2:51 PM, Jozef Hartinger <span dir="ltr"><<a href="mailto:jharting@redhat.com" target="_blank">jharting@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"><div class="im">
<div>On 11/19/2013 03:09 AM, Muhammad Bhutto
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>Hi All,</div>
<div><br>
</div>
<div>Can you please explain me this one, I have confusion which
one is better.</div>
<div><br>
</div>
<div>1.<br>
</div>
<div><br>
</div>
<div>
<div>Bean<MyBean> bean = (Bean<MyBean>)
beanManager.resolve(beanManager.getBeans(MyBean.class));</div>
<div>MyBean= (MyBean) beanManager.getReference(bean,
bean.getBeanClass(),
beanManager.createCreationalContext(bean));</div>
</div>
</div>
</blockquote></div>
This one gives you a new instance of a client proxy. The client
proxy will forward method calls to the current contextual instance
of a particular context. You can therefore obtain the proxy once and
keep it and the method calls will be invoked on the current instance
(e.g. current request). It is also useful if the contextual instance
is not serializable - the client proxy will be and will reconnect
after you deserialize it.<div class="im"><br>
<blockquote type="cite">
<div dir="ltr">
<div><br>
</div>
<div>2.</div>
<div><br>
</div>
<div>
<div>Bean<MyBean> bean = (Bean<MyBean>)
beanManager.resolve(beanManager.getBeans(MyBean.class));</div>
<div>MyBean bean =
beanManager.getContext(bean.getScope()).get(bean,
beanManager.createCreationalContext(bean));</div>
</div>
</div>
</blockquote></div>
This obtains the target instance without a client proxy. You may
still see a Weld's proxy in the class name but that is an enhanced
subclass that provides interception and decoration. If the bean is
not intercepted nor decorated this will be a plain instance of the
given bean.<br>
<br>
Usually (1) is more suitable unless you have a special use-case
where you need to access the target instance directly (e.g. to
access its fields).<br>
<blockquote type="cite"><div class="im">
<div dir="ltr">
<div><br>
</div>
<div><br>
</div>
<div>As i know BeanManager.getReference() always creates a
whole new proxy instance, while the Context.get() reuses an
existing proxy instance if already created before.<br>
</div>
<div><br>
</div>
<div> Is BeanManager.getReference() is more use full than
Context.get() ??<br>
</div>
<div><br>
</div>
<div>Thanks</div>
<div><br>
</div>
<div>Muhammad Asif Bhutto</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div><pre>_______________________________________________
weld-dev mailing list
<a href="mailto:weld-dev@lists.jboss.org" target="_blank">weld-dev@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/weld-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a></pre>
</blockquote>
<br>
</div>
</blockquote></div><br></div>