0

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 }
javaNoober
  • 1,338
  • 2
  • 17
  • 43

3 Answers3

2

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.

Mikael Couzic
  • 12,283
  • 5
  • 22
  • 16
  • I tend to have a dedicated Service layer, pretty similar to your concept of Business objects. The Service layer does any heavy lifting (except for anything reusable which I refactor into utility classes...), and I try to keep both my handler and DAO classes pretty thin. – Jason Sep 27 '11 at 10:47
  • Ye you both are right, just wasn't sure where I connect my Service to the Handler, because I know I have dependency injection with GIN already, just don't know how, trying answer above – javaNoober Sep 28 '11 at 04:37
1

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;
}
Sydney
  • 11,964
  • 19
  • 90
  • 142
  • Never crossed my mind that the constructor there was for this purpose, I'll give it a try, thx – javaNoober Sep 28 '11 at 04:33
  • Ok, didn't worked, message says 1) No implementation for com.test.domain.Service was bound. I imagine I need to do something to my Service as well. Can you give me a hand? – javaNoober Sep 28 '11 at 04:44
0

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