openwebbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Struberg <strub...@yahoo.de>
Subject ...Re: Lazy load a bean
Date Wed, 16 Oct 2013 20:02:53 GMT
Hi Desmond!

Depends what you understand under the term 'Bean'. 

Let me explain: The CDI spec defines Bean<T> as meta-information about instances to
be created. Kind of a factory rule information.
This is different to what CDI understands under 'Contextual Instance' which means the real
instances of your e.g. @ApplicationScoped MailService, the @RequestScoped User, etc

There is also a 3rd term, the 'Contextual Reference' which is simply a delegating proxy to
your contextual instances. This is what you normally get injected if you use 

@Inject MailService mailSvc; 


Do you have some samples or give us some hint about what you like to solve?
It is not easily possible in CDI to lazily change Bean<T> stuff, because those get scanned
at boot time, validated, etc.

It is of course possible to lazily load Contextual References. You can use the Instance<T>
for this:

@Inject
@Any // to get all qualifiers

private Instance<MailService> mailServiceProvider;

...
mailServiceProvider.isAmbiguous()...


If you like to have even more control, then you can use the BeanManager#getBeans() to get
all the Bean<T> information and later on use BeanManager#getReference(..) to get the
exact contextual instance you were looking for.

Feel free to ping back on any further question.


LieGrue,
strub




>________________________________
> From: Dessie K <desmond.kirrane@gmail.com>
>To: user@openwebbeans.apache.org 
>Sent: Wednesday, 16 October 2013, 21:03
>Subject: Lazy load a bean
> 
>
>
>Hi,
>
>
>How can I lazy load beans?
>
>
Mime
View raw message