-
1. Re: Injection into Enums!
pmuir Jun 29, 2009 2:28 PM (in response to niravshah)I guess it is possible to support injection into static fields in Enums - please file a feature request in WBRI...
-
2. Re: Injection into Enums!
gavin.king Jul 1, 2009 6:50 AM (in response to niravshah)Would you mind showing us an example of what your DSL looks like? I've recently been toying with some ideas like that for a typesafe navigation facility for Seam2. I'd like to see what you guys have come up with.
-
3. Re: Injection into Enums!
genman Jul 1, 2009 9:14 PM (in response to niravshah)I would assume the injection might work along the lines of this:
public enum ColorPreferences { BACKGROUND, FOREGROUND; @Current private EntityManager em; @Current private Customer customer; /** * Returns the color for the customer for this component. */ public Color getColor() { em.query(...).getSingleResult(); } }
-
4. Re: Injection into Enums!
genman Jul 1, 2009 11:28 PM (in response to niravshah)Just tested this, and it doesn't work. The deployment scanner skips enum classes. Is this something specified in JSR 299?
I'm not really sure how an enum type or its enumerated values might be used as a bean.
One idea:
For every enumerated type, a bean is created for each of the enumerated values. (Expensive?)
Each bean automatically has scope @ApplicationScope
Each bean has a default name, which is the name of the unqualified class name, plus the name. (For example, com.foo.ColorPreferences.BACKGROUND.)
To reference an enumerated type as a bean, you can use EL, or you can of course inject it using a binding type, like @Current.
-
5. Re: Injection into Enums!
pmuir Jul 2, 2009 1:49 AM (in response to niravshah)Enum's aren't managed beans (see 3.1.1,
It has an appropriate constructor...
- Enum's don't have callable constructors), so 299 doesn't require them to be available for injection etc.Atm I haven't quite finished implementing the third party SPI for injection (done either early next week, or mid July as I am on PTO in early July), but once that is done, you should prototype a third party extension that supports your ideas and see if people like it.
-
6. Re: Injection into Enums!
genman Jul 2, 2009 7:43 PM (in response to niravshah)Would like to toy around with this, but my new employer's prohibiting open source contributions ATM. We'll see.
The comprehension problem I see with enum values is they would need to be always referenced through some sort of injection or the EL, and not through the name. This is quite non-intuitive.
The main benefit is a developer can easily/quickly create a number of grouped, named, singleton beans and also wouldn't need to use @Produces or create them through XML.
-
7. Re: Injection into Enums!
pmuir Jul 3, 2009 10:40 AM (in response to niravshah)
Elias Ross wrote on Jul 02, 2009 19:43:
The comprehension problem I see with enum values is they would need to be always referenced through some sort of injection or the EL, and not through the name. This is quite non-intuitive.Right, this is why I feel it's something not to support.