java - 使用多个注入(inject) DAO 时的最佳实践是什么

标签 java spring gwt jpa guice

我突然想到将我的服务器端任务编写为一个大服务,并将所有 dao 对象注入(inject)该服务中 - 如下所示:

public class MyServiceImpl extends RemoteServiceServlet implements MyService {
@Inject 
MyDAO1 myDAO1;
@Inject 
MyDAO2 myDAO2;
@Inject 
MyDAO3 myDAO3;

...
//20  methods
//
}

是否需要一项大型服务,或者是否有其他更好的模式?

最佳答案

您应该为每个任务“域”构建一个服务。例如,用户管理服务,其方法允许注册新用户、发送恢复密码电子邮件、暂时禁用用户、获取当前启用的用户列表等。

我建议您看一下 Martin Fowler 的企业应用程序架构模式 ( http://martinfowler.com/books/eaa.html ) 中描述的 ServiceLayer 模式。

A Service Layer defines an application's boundary [Cockburn PloP] and its set of available operations from the perspective of interfacing client layers. It encapsulates the application's business logic, controlling transactions and coor-dinating responses in the implementation of its operations (http://martinfowler.com/eaaCatalog/serviceLayer.html)

关于java - 使用多个注入(inject) DAO 时的最佳实践是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18743511/

相关文章:

java - jvm运行垃圾收集时Kubernetes Pod内存使用率不下降

Java jar : Executing a method only upon opening the jar for the first time?

java - 使用 FLAG_SECURE 允许屏幕截图

java - 包 org.springframework.cloud.netflix.zuul 不存在

javascript - 使用 Spring Boot API 的 React Admin 中的 X-Total-Count 缺少 header 错误

java - GWT 开发和设计模式

java - 如何使用Jena TDB存储本地版本的Linked Movie Database

java - 如何在 Spring JMS 监听器中从 JMS 消息获取自定义属性

android - 使用手机摄像头作为 GWT 的扫描仪?

css - GWT:如何在 Cell List 中实现 Accordion 效果?