[webbeans-dev] Replacement pattern for Manager.getInstanceByType
Dan Allen
dan.j.allen at gmail.com
Tue Jul 21 11:18:07 EDT 2009
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/weld-dev/attachments/20090721/1168447f/attachment.html
More information about the weld-dev
mailing list