-
1. Re: What is a moment when a bean is being initialized?
wdfink Jul 5, 2014 7:41 AM (in response to cottonwood)The injection happen if the container create the instance.
So both injected Objects are initialized before a method of this class will be invokend and also before @PostConstruct method is invoked.
Does that makes sense to you?
-
2. Re: What is a moment when a bean is being initialized?
cottonwood Jul 7, 2014 3:05 AM (in response to wdfink)Yes, I don't like it much that objects I don't need at the moment are already initialized. How to design a Factory class in this case? For example, I have an incoming parameter and based on this parameter I want to inject different implementations of an interface? I thought I could declare several injection points and in the producer method could return necessary implementation. Can you make some suggestions how to design Factory class with Weld?
-
3. Re: What is a moment when a bean is being initialized?
mkouba Jul 7, 2014 3:20 AM (in response to cottonwood)Well, it's not entirely true that bean instances are always created when the injection is performed. For a normal scoped bean (e.g. @RequestScoped) a client proxy is usually injected. And CDI implementations are allowed to lazily initialize such a proxy (see also https://issues.jboss.org/browse/CDI-125). It means that the bean instance may not be initialized at all (if not used).
cottonwood as to your use case, you can try to use programmatic lookup (see http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#programmatic_lookup). However, pay attention to the
javax.enterprise.inject.Instance
lifecycle (inproper use may result in memory leaks - https://issues.jboss.org/browse/WELD-920).