0 Replies Latest reply on Nov 7, 2012 11:10 AM by nva

    errai+guice: installing guice ServletModule, custom bindings

    nva Newbie

      I needed to make injection work in servlets in an errai application. The dependency tree includes services that have a dependency on the errai bus (they broadcast on the bus).

       

      I run into a wall on several fronts:

       

      1. The injector

       

      a. Problem of installing a module

       

      When creating a new injector (as described here: https://code.google.com/p/google-guice/wiki/ServletModule), it does not have access to the Errai bindings. The injection of anything with an Errai dependency will fail.

       

      Looking at the Errai sources, I found no way of getting hold of either the Module or the injector. No handles are kept to them. I do see that the approach is the opposite: Errai extensions can define bindings that are added to the injector during bootstrap. This seems to be restrictred to supporting provider bindings only, however.

       

      Question: is there any way of installing a module from an extension?

       

      b. Problem of injector context

       

      When creating a new injector with Guice.createInjector, it is going to have its own injection context. Singletons are singletons within the injection context only and my new injector is going to create new instances of all of them.

       

      Question: would it be possible to maintain and make accessible a single injector from the Errai server-side bootstrap that could be used for

      - adding child injectors (this would solve the problem in a.)

      - for injection from servlets, quartz jobs, anything that is outside of the environment created by the Errai bootstrap

       

      2. Timing

       

      So far in my testing my servlet's init() method has always been called _before_ the Errai server-side bootstrap completed. Same problem with ContextListeners.

       

      Question: would there be any way of getting notification that the server-side bootstap has completed?

       

      Thanks!