Is there a way to know if a state is active without catching ContextNotActiveException?

前端 未结 1 403
醉酒成梦
醉酒成梦 2021-02-09 08:37

I would like to know if the RequestScoped context is currently active in a method or not.

At the moment, here is what I do :



        
相关标签:
1条回答
  • 2021-02-09 09:32

    No, the only option we have in CDI 1.0 is to catch the ContextNotActiveException.

    Your solution should work.

    This actually ends up being a problem because scope implementation is not available for injection.

    E.g. You can't just @Inject RequestScopedContextImpl rq; and check the rq.isActive() method, because we don't have access to that class without knowing the implementation details of CDI itself.

    0 讨论(0)
提交回复
热议问题