Java EE 6 @Inject lazy?
cdi, dependency-injection, inject, java, java-ee-6
Solution
What about using
@Inject
private Instance<?> lazyProvider;
?
That allows Getting instance of "?" when actually needed via
lazyProvider.get();
Problem
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?