Search code examples
gwtdispatchgwt-gingwt-platform

GWT-Platform: where the business logic should go?


I just got the grip on GWTP and the MVP, GIN and Dispatch.

With dispatch there is a Handler class which defines what the action does and returns something accordingly.

So far I found myself with a case where I have 2 actions that require to execute the same method. For which I believe ActionHandling is not where the bussiness logic goes, but that it should go in a layer behind it which pass something to it somehow

How should I layout my logic? I would like to use Hibernate later on btw.

EDIT:

as a note, applying the answers provided on practice, what needs to be done is:

1.- Create a module class that extends AbstractModule, this contains

bind(Service.class).to(ServiceImpl.class);

2.- on your GuiceServletcontextListener add your serviceModule to the getInjector method return:

return Guice.createInjector(new ServerModule(), new DispatchServletModule(), new ServiceModule());

3.- On yours actionHandlers constructors have something like this

@Inject
  TestHandler(Service service) { this.service=service }

Solution

  • Is MyService an interface? If yes, you forgot to bind it inside Guice.

    Personnaly I use DAOs to put my logic between ActionHandlers and my persistence framework (Hybernate, Objectify, Twig-Persist, etc.)