开发者

Correct use of Repository / Service Classes

开发者 https://www.devze.com 2023-02-11 00:41 出处:网络
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, engin

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 ar开发者_开发问答e correct. A web service provides the data in JSON format from which I can construct an RMAobject. 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.


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.

0

精彩评论

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

关注公众号