<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 11/19/2013 03:09 AM, Muhammad Bhutto
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAAX2nWZ9PVFYz_YWVO8G=rc5wVGLZ3iEpsyaAcJY2ivh26oFuw@mail.gmail.com"
      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&lt;MyBean&gt; bean = (Bean&lt;MyBean&gt;)
            beanManager.resolve(beanManager.getBeans(MyBean.class));</div>
          <div>MyBean= (MyBean) beanManager.getReference(bean,
            bean.getBeanClass(),
            beanManager.createCreationalContext(bean));</div>
        </div>
      </div>
    </blockquote>
    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.<br>
    <blockquote
cite="mid:CAAX2nWZ9PVFYz_YWVO8G=rc5wVGLZ3iEpsyaAcJY2ivh26oFuw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>2.</div>
        <div><br>
        </div>
        <div>
          <div>Bean&lt;MyBean&gt; bean = (Bean&lt;MyBean&gt;)
            beanManager.resolve(beanManager.getBeans(MyBean.class));</div>
          <div>MyBean bean =
            beanManager.getContext(bean.getScope()).get(bean,
            beanManager.createCreationalContext(bean));</div>
        </div>
      </div>
    </blockquote>
    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
cite="mid:CAAX2nWZ9PVFYz_YWVO8G=rc5wVGLZ3iEpsyaAcJY2ivh26oFuw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div><br>
        </div>
        <div>As i know &nbsp;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>&nbsp;Is&nbsp;BeanManager.getReference() is more use full than
          &nbsp;Context.get() ??<br>
        </div>
        <div><br>
        </div>
        <div>Thanks</div>
        <div><br>
        </div>
        <div>Muhammad Asif Bhutto</div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
weld-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/weld-dev">https://lists.jboss.org/mailman/listinfo/weld-dev</a></pre>
    </blockquote>
    <br>
  </body>
</html>