开发者

GWT-Platform: where the business logic should go?

开发者 https://www.devze.com 2023-04-08 03:48 出处:网络
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.

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 }


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;
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号