Domanda

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 }
È stato utile?

Soluzione

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.)

Altri suggerimenti

Business logic should be in your business objects, which are independent from your Handler classes. Try to design your business layer in a technology-agnostic way. The handlers delegate all significant processing to the business objects, so they (the handlers) should be pretty thin actually.

You could try to inject the service layer into the handler. The service can be created as a singleton.

@Inject
public MyHandler(MyService service) {
  this.service = service;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top