[webbeans-dev] Replacement pattern for Manager.getInstanceByType
Pete Muir
pmuir at redhat.com
Tue Jul 21 11:22:01 EDT 2009
You should always use the same creational context for the lifecycle of
the bean instance (for creation and destruction) otherwise generate a
new one.
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