[weld-dev] Initialising newly registered beans

Matt Drees matt.drees at gmail.com
Mon Nov 30 08:09:33 EST 2009


Oops, I forgot to reply-all:

On Mon, Nov 30, 2009 at 12:45 AM, Matt Drees <matt.drees at gmail.com> wrote:

>
>
> On Sun, Nov 29, 2009 at 6:21 PM, Peter Royle <
> howardmoon at screamingcoder.com> wrote:
>
>> Hi,
>>
>> I've got this extension which I'm using to explicitly register all of the
>> managed beans used by Weld Java SE:
>>
>> public class WeldSEBeanRegistrant implements Extension
>> {
>>
>>    private final ClassTransformer transformer = new ClassTransformer(new
>> TypeStore());
>>
>>    public void registerWeldSEBeans(@Observes AfterBeanDiscovery event,
>> BeanManagerImpl beanManager)
>>    {
>>        addBean(ShutdownManager.class, beanManager, event);
>>        addBean(ParametersFactory.class, beanManager, event);
>>    }
>>
>>    private void addBean(final Class<?> klass, BeanManagerImpl beanManager,
>> AfterBeanDiscovery event)
>>    {
>>        WeldClass<?> weldClass = WeldClassImpl.of(klass, transformer);
>>        ManagedBean<?> bean = ManagedBean.of(weldClass, beanManager);
>>        event.addBean(bean);
>>        bean.initialize( ___environment___);
>>    }
>> }
>>
>>
> Well, I believe the portable way to do this is:
>
>
>
>    private void addBean(final Class<?> klass, BeanManagerImpl beanManager,
> AfterBeanDiscovery event)
>    {
>        Bean newBean = createBean(beanManager.createInjectionTarget(klass),
> beanManager.createAnnotatedType(klass));
>        beanManager.addBean(newBean);
>    }
>
> where createBean() can either manually create an implementation of Bean
> that delegates appropriately to the InjectionTarget and AnnotatedType, or
> you can use BeanImpl from the weld-extensions project  (you'd have to throw
> in an extraneous Reannotated() call, but no biggie).
> I think if you do it this way, you won't have to worry about Weld's
> ManagedBean.initialize().
>
> Haven't tried it though.
>
> -Matt
>
>
(Also, beanManager.createInjectionTarget takes should take the created
AnnotatedType, not klass)


>
>
>>
>> Cheers,
>>
>> Pete.
>>
>>
>>
>> _______________________________________________
>> weld-dev mailing list
>> weld-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/weld-dev
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/weld-dev/attachments/20091130/ead14b82/attachment.html 


More information about the weld-dev mailing list