Most commonly, JSF applications uses dependency injection by annotating private fields with @Inject. We can inject directly an instance of another class (bean) or we can inject an javax.enterprise.inject.Instance and use the get() method to obtain the needed instance:
@Named
@RequestScoped
public class TheBean {
private static final Logger LOG = Logger.getLogger(TheBean.class.getName());
@Inject
private Foo foo;
//private Instance<Foo> foo;
@Inject
private Buzz buzz;
//private Instance<Buzz> buzz;
@Inject
private Bizz bizz;
//private Instance<Bizz> bizz;
public void callFooBuzzBizz() {
LOG.info("TheBean#callFooBuzzBizz() called ...");
Messages.addGlobalInfo("TheBean#callFooBuzzBizz() called ...");
foo.fooify();
buzz.buzzify();
bizz.bizzify();
// foo.get().fooify();
// buzz.get().buzzify();
// bizz.get().bizzify();
}
}
The complete example is available here.