2 Replies Latest reply: Apr 21, 2012 2:34 AM by Aaron Anderson RSS

Access to InjectionPoint from custom CDI Context Scope?

Aaron Anderson Newbie

Given a Qualifer @FooId:

 

@Qualifier                   
@Target({ ElementType.PARAMETER })                    
@Retention(RetentionPolicy.RUNTIME)                    
public @interface FooId {      
  String value(); 
} 

 

 

and Custom Scope @FooScope:

 

@Scope                    
@Retention(RUNTIME)                    
@Target(TYPE)                    
public @interface FooScope {  } 

 

 

and Custom Object Foo:

 

@FooScope                   
 public class Foo {  }
 

 

 

and  injection target Bar:

 

public class Bar {                          
  @Inject                           
  @FooId("0")                           
  Foo foo;                      
} 

 

 

 

I would like to have access to the Injection Point foo in Bar so I can read the value of the @FooId annotation and return the appropriately scoped object. While this can be done with providers:

 

 

@Produces         
public Foo create(InjectionPoint ip, BeanManager mgr) {
 }

 

 

there seems to be no way to do this in a custom scope:

 

 

@Override         
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {         
}

 

 

 

where contextual is the annotated Bean type. Is this a limitation of CDI and if so will it be addressed in CDI 1.1?

 

Thanks!


Aaron