Because I am constantly busy working on something, I have never had time to actually put everything in words and pictures. But, since you got here, then you must have already seen some part of my work - and this is the way I’m talking.I'm 23, born in Romania, student at UPG Romania in software development field. I started from 0, mostly with basic stuff, and I’m evolving every day to an expert. I'm focused on freelancing projects, from small websites, to really heavy stuff. I know that I look and act differently from most developers, but this is why you will love to work with me! Constantin has posted 42 posts at DZone. You can read more from them at their website. View Full User Profile

When to use a CDI producer field or method

04.21.2011
| 4638 views |
  • submit to reddit

 Conforming to the official specification, a producer field can be used:

• instead of a simple getter method
• for declaring Java EE resources

Moreover, a producer method can be used – producer methods acts as sources of bean instances:

• to inject non-beans objects (expose any JDK class as a bean)
• to inject objects that have type that vary at runtime (vary the implementation of a bean type at runtime)
• to inject objects that requires some custom initialization that the bean constructor does not perform (define multiple beans, with different scopes or initialization, for the same implementation class).

From http://e-blog-java.blogspot.com/2011/04/when-to-use-cdi-producer-field-or.html

Published at DZone with permission of its author, Constantin Alin.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: