I have a producer method that creates instances of—let's say—Person
.
The instance that this method creates is of type PersonBean
and quite obviously implements Person
.
This class has an initializer method in it:
@Inject
public void setSomething(final Something something) {
// whatever
}
There is also a Something
implementation on the classpath in a bean archive that should be a candidate for injecting here.
I've observed that this implementation is injected into an appropriately-annotated field of another non-producer-method-produced object, so I know Weld is finding it, it's valid, etc. etc.
The specification is not clear (to me) on whether or not my producer method's return value will then also have Weld/container-provided dependency injection applied to it.
I am certainly observing that this initializer method is not called automatically.
Boiled down, my question is: if I am producing an object, then does that mean my producer method must take care of all initialization of that object, or (what I'd expect instead) is my producer method only responsible for instantiation?
if I am producing an object, then does that mean my producer method must take care of all initialization of that object, or (what I'd expect instead) is my producer method only responsible for instantiation?
3.3. Producer methods
A producer method acts as a source of objects to be injected, where:
- the objects to be injected are not required to be instances of beans,
This should answer your question: If you are instantiating a new object (using new
) you will have to take care of the initialization.
(A probably more common usecase of producer methods is to configure and produce an existing bean into a certain scope...)