[webbeans-dev] Replacement pattern for Manager.getInstanceByType

Peter Royle howardmoon at screamingcoder.com
Tue Jul 21 20:17:31 EDT 2009


> > You just use the manager to create a CreationalContext for the bean.
> >
> > beanManager.createCreationalContext(bean)
> >

Sounds like just what I need, thanks.

> You should always use the same creational context for the lifecycle of  
> the bean instance (for creation and destruction) otherwise generate a  
> new one.

I'm only going to generate the bean once during the life of the app
(it's @ApplicationScoped). IIUC, thereafter the CreationalContext should
be ignored. 

Now, is the CreationalContext then stored with the bean instance and
used for destruction automatically (seems that way in
AbstractMapContext.destroy(Contexual) )?

Thanks,

Pete.

> 
> On 21 Jul 2009, at 16:18, Dan Allen wrote:
> 
> > On Tue, Jul 21, 2009 at 10:50 AM, Peter Royle <howardmoon at screamingcoder.com 
> > > wrote:
> > Sorry to drag this up again, but this has changed now that
> > manager.getReference(...) requires a CreationalContext, about which I
> > know very little. I'll try reading the latest spec soon, but in the
> > meantime if anyone has any silver bullets please let me know.
> >
> > I'm currently using this utility method:
> >
> >     public static <T> T getInstanceByType(BeanManager manager,
> > Class<T> type, Annotation... bindings) {
> >         return (T)manager.getReference(
> >                 manager.getBeans(type).iterator().next(), type, null);
> >     }
> >
> > Obviously it's that null at the end (where CreationalContext should
> > be) that's causing the problem.
> >
> > You just use the manager to create a CreationalContext for the bean.
> >
> > beanManager.createCreationalContext(bean)
> >
> > If an instance already exists, the CreationalContext is not used.  
> > Someone correct me if I am wrong.
> >
> > -Dan
> >
> > -- 
> > Dan Allen
> > Senior Software Engineer, Red Hat | Author of Seam in Action
> > Registered Linux User #231597
> >
> > http://mojavelinux.com
> > http://mojavelinux.com/seaminaction
> > http://in.relation.to/Bloggers/Dan
> > _______________________________________________
> > webbeans-dev mailing list
> > webbeans-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/webbeans-dev
> 




More information about the weld-dev mailing list