• Post Reply Bookmark Topic Watch Topic
  • New Topic

is it possible to detect a CDI manged bean's scope at runtime?

 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to detect a CDI manged bean's scope at runtime?

any hints will be more than welcome!

 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to introspect the annotations. But that's no guarantee. CDI-, JSF- and Spring-managed beans all allow you to use one form of annotation or another to define how they should be automatically constructed, but that's actually just their defaults. The annotations won't kick in, for example, if you explicitly use the "new" operator to construct a bean and you could then store a bean annotated for Request Scope in Session Scope (or vice versa. Nor would it help if you used the XML wiring for the framework in question (which overrides annotation-based construction).

Since the beans themselves are POJOs, there's no way to work back from a random instance of that bean.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!