This content has been marked as final.
Show 2 replies
-
1. Re: Can you inject in produced object in CDI?
mkouba Jun 30, 2014 4:01 AM (in response to ericjvandervelden)Hi Eric,
a producer method is fully responsible for creating a new instance of a an object. In other words, the CDI container only takes the result of the producer method. However, a producer method may have any number of parameters and all those parameters are injection points.
So one way you could solve this:
@Named @Produces public My getMy(@Random int randomNumber){ return new My(randomNumber); }
The other way would be to use the CDI SPI to create an unmanaged instance. But I'm not so sure this makes much sense. I mean, what is the reason to use a producer then?
-
2. Re: Can you inject in produced object in CDI?
ericjvandervelden Jul 6, 2014 4:54 AM (in response to mkouba)Thank you very much.