Frage

I'm using successfully GIN on my GWT projet. Now my RPC service will need data from other layer (Business Logic --> Data Access), in the old time I would have done singleton services with needed methods. Something like MyGwtServiceImpl.getData() --> MyServerSideService.getData() --> MyDaoGetDataFromDB()

But nowadays singleton are not really appreciated and I would like for testing purpose use the injection method.

I know all I need to know is install GUICE for server side, but I'm not really sure where the creation of the injector should be done. Usually it would be done in a main method, but here I'm using GWT.

Will there be conflict between GIN and GUICE lib?

Where should I put the injector creation ? in the onModuleLoad ? I'm not sure since my application will be divided in several.

Thanks for helping!


Summary :

  • Follow the tutorial given by Thomas (The answer)
  • But for injection to work, don't forget to replace (delete in fact) in web.xml :

    <servlet>
        <servlet-name>MyService</servlet-name>
        <servlet-class>com.myapp.MyServiceImpl</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyService</servlet-name>
        <url-pattern>/com.myapp/MyService</url-pattern>
    </servlet-mapping>
    
  • By in a Guice module :

     serve("/com.myapp/MyService").with(MyServiceImpl.class);
    
War es hilfreich?

Lösung

You'd want to create your Injector in a ServletContextListener. Have a look at http://code.google.com/p/google-guice/wiki/ServletModule

There's absolutely no conflict between GIN (Guice for GWT, on the client-side) and Guice (on the server-side).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top