Hi CDI experts,

I wanted to know if there was anything in CDI or DeltaSpike to help make custom 
CDI Contexts injectable/managed?

class MyCustomContext implements Context {
    @Inject
    private MyService myService;
    ...
}

public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager 
beanManager) {
    MyCustomContext context = ... // what should I do here?
    event.addContext(context);
}

What would be the best way to obtain/initialize an instance of MyCustomContext 
in my extension?

- Would it be legal/performant to declare the context as 
@ApplicationScoped/@Singleton and resolve it through the BeanManager before 
calling AfterBeanDiscovery.add()?
- Should I better use something like new Unmanaged<>(beanManager, 
MyCustomContext.class).newInstance().produce().inject().postConstruct().get();
- In early versions of CDI (don't remember if it was with Weld or OWB), I could 
do afterBeanDiscovery(@Observes AfterBeanDiscovery event, MyCustomContext 
context) but I don't think this was really permitted by the specification.
- Any other option?

Thanks,
Xavier

Reply via email to