Reputation: 3147
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.
Upvotes: 9
Views: 14601
Reputation: 101176
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.
Upvotes: 17