3 Replies Latest reply on Mar 13, 2013 5:35 AM by shadogray

    Injection in RpcInterceptor not working

    shadogray

      I am trying to use dependency injection in an RpcInterceptor:

       

      @Dependent

      public class EchoInterceptor implements RpcInterceptor {

       

          @Inject

          private Event<Message> message;

       

           @Inject 

           private SimpleEvent simpleEvent;

       

          @Override

          public void aroundInvoke(RemoteCallContext context) {

              GWT.log("intercepted"+message);

              context.proceed();

          }

      }

       

      Unfortunately message is always null. The simpleEvent is correctly injected.

      Is it not possible to use Event in Interceptors?

       

      Thanks,

      Thomas

        • 1. Re: Injection in RpcInterceptor not working
          csa

          This is not supported in Errai 2.x but will soon be supported in Errai 3. For now you will need to use the BeanManager API to look up bean instances in interceptors: IOC.getBeanManager().lookupBean(SimpleEvent.class)

           

          To provide some context: The remote interceptors (for RPC and REST calls) need to work without IOC (in case you build a plain Errai Bus or Errai JAXRS app). So, at rebind time we need to detect that Errai IOC will be available and then generate different interceptor code.

           

          Cheers,

          Christian

          • 2. Re: Injection in RpcInterceptor not working
            csa

            I just realized you wrote that SimpleEvent was correctly injected, but I don't think that's possible, since the interceptor instance is created using the new operator. The simplest workaround to get to an injected event right now is to inject it into another bean and then look up that other bean using the BeanManager API as described above.

            • 3. Re: Injection in RpcInterceptor not working
              shadogray

              works like a charm :-)

              Thank you,

              Thomas