Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE 6 @Inject lazy? [duplicate]

I am doing some refactoring and reviewing of the application that we are currently developing. While doing this I found that more beans are injected and I think making they loading in an lazy manner would be better suited for their purpose. I am using Java EE 6 and tend to use more CDI than EJB injection.

So the question is whether it is possible to inject the beans lazily and if so, how can you do it?

like image 397
Olimpiu POP Avatar asked Apr 10 '13 08:04

Olimpiu POP


1 Answers

What about using

@Inject
private Instance<?> lazyProvider;

?

That allows Getting instance of "?" when actually needed via

lazyProvider.get();
like image 70
Jan Galinski Avatar answered Oct 23 '22 22:10

Jan Galinski