[jboss-user] [JBoss Seam] - Injection woes

texan do-not-reply at jboss.com
Tue Aug 15 14:41:13 EDT 2006


How about adding a "@Singleton" annotation to Seam?

Right now, I use this pattern:

    @In(create = true)
  |     @Out(scope = APPLICATION)
  |     private SomeClass myClass;

Obviously, the target class itself isn't implemented as a singleton in this case, since it needs a public constructor.

My point is, why perform an "outjection" every time when I'll only ever create it once?  That is, the "@Out" (and create=true) is only truly needed once.  I have no interest in reassigning "myClass" to a new instance and have that one pushed into the  context.  In fact, I'd like an error if I tried, preferably even a compiler error.  [side note, can an annotation cause an instance variable to be redefined as "final?"]

I'm being picky, but it would be nice to be able to do this:

    @Singleton
  |     private SomeClass myClass;

or even

    @Singleton (method="getInstance")
  |     private SomeClass myClass;

or possibly

    @Singleton
  |     private final SomeClass myClass;
(if the annotation itself can't enforce the "final" notion)

I would be quite content to do this myself, if I knew how.  I'm assuming that, in addition to creating the annotation interface, I'd need to create an interceptor that is always called when my session beans are instantiated, and that interceptor would need to scan the member variables for this annotation and do the work of checking for an existing instance in the app context, etc.

Presumably it would use the fully qualified class name as the context key rather than the instance variable name.

Sadly, I haven't delved into interceptor creation just yet...  Besides, this seems (in my selfish opinion) to be a Seam-worthy annotation.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3965343#3965343

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3965343



More information about the jboss-user mailing list