正确使用存储库/服务类
我正在开发一个相当轻量级的客户端应用程序(.Net 中的桌面应用程序,因为将来可能需要连接到其他应用程序),用于为工程师跟踪企业内的 RMA,工程师将查看和更新应用程序中的状态,客户将在网站上创建/查看 RMA。
我想知道我对服务和存储库类的预期使用是否正确。 Web 服务提供 JSON 格式的数据,我可以从中构建 RMA 对象。此 Web 服务通过 http://myRMA.com/repairs/2234/RMA.JSON
访问,
获取 RMA 的代码是否位于 RMARepository
类中,方法如下GetRMA(int RMAId)
,RMARepository
是否应该遵循单例设计模式?
然而,如果 RMA 已更新,即项目正在检查并等待报价接受,则这是否在服务类中完成,该服务类调用 RMARepository 来提交更新。 IsExists(int RMAId)
会在此服务类中还是在存储库中?
我熟悉演示-应用程序(逻辑)-数据访问-数据(数据库)架构,也熟悉MVP。但我确实想知道 Service
类适合在哪里。
Im working on a fairly light weight client application (desktop app in .Net as connect to other applications maybe needed in the future) for tracking of RMAs within a business for the engineers, engineers will view and update the status in the application, customers will create/view RMAs on the website.
I want to know if my intended use of service and repository classes are correct. A web service provides the data in JSON format from which I can construct an RMA
object. This web service is accessed by http://myRMA.com/repairs/2234/RMA.JSON
Would the code to get the RMA sit within RMARepository
class with a method like GetRMA(int RMAId)
, and should the RMARepository
follow the singleton design pattern?
Whereas if the RMA is updated, i.e. Item is inspecting and pending a quote acceptance, is this completed in a service class, which calls a RMARepository to submit an update. Would the IsExists(int RMAId)
be in this service class or be in the repository?
I am familiar with Presentation - Application (Logic) - Data Access - Data (Database) artitecture, and also with MVP. But i do wonder where the Service
classes fit in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
存储库类仅用于访问和存储数据库中的信息。他们不应该有其他逻辑。
服务用于从数据源(很可能是存储库)获取信息、处理信息并将结果返回给调用者。
一个服务类可以使用多个存储库来实现所需的结果。在这一层中,您还可以拥有一个事件系统,该系统可以允许一个服务在另一个服务生成事件时采取操作。
一个示例是 UserService 调用 FeedService 为每个新创建的用户创建一个新的 RSS 提要项。
Repository层可以用ORM(例如nhibernate)来表示。
The repository classes are only used to access and store information in the database. They should have no other logic.
Services are used to fetch information from a data source (most likely a repository), process the information and return the result to the caller.
A service class can use multiple repositories to achieve the wanted result. In this layer you can also have a event system which can allow one service to take actions when another service have generated an event.
An example would be that the the UserService calls the FeedService to create a new RSS feed item for each newly created user.
The Repository layer can be represented by a ORM such as nhibernate.