I am trying to develop my own CDI scope with an extension. I would like to extend the CDI scope. My scope is to be conversation scope at most. That is, I want my the lifespan of my bean end if the conversation ends, but I want to be able to end it sooner under certain circumstances.
I cannot find good documentation on how to do this.
I created an extension
public class FoobarScopedExtension implements Extension, Serializable {
private static final long serialVersionUID = 1L;
public void addScope(@Observes final BeforeBeanDiscovery event) {
event.addScope(FoobarScoped.class, true, false);
}
public void registerContext(@Observes final AfterBeanDiscovery event) {
event.addContext(new FoobarScopedContext());
}
}
And I created a context. But within my context, I cannot figure out how to see the actual conversation or how to tie my scope to the conversaiton so that if the conversaiton ends, the beans with my scope are destroyed as well.
I seem to be missing something...
public class FoobarScopedContext implements Context, Serializable {
@Override
public <T> T get(Contextual<T> contextual) {
//code...
//somehwere here, I need to be able to tie instances to conversations to see what bean is tied to what conversation
//somehow I should be able to make it so the bean can be cleaned up when the conversation ends
}
}
Aucun commentaire:
Enregistrer un commentaire