Service layer vs business layer - differences?

Ashok Padmanabhan picture Ashok Padmanabhan · Oct 12, 2011 · Viewed 14.7k times · Source

I have been doing a lot of reading on service layers and business layers and how they compare. I have a read a number of the threads here on StackOverflow on the topic and i still find myself confused as to the differences between the two if there are any. To me it seems that its mainly a naming convention where one dev calls the middle layer a business layer and another may call it a service layer. From the code i have seen here on SO and around the web they seem to do mainly the same thing - that is query the repository, maybe do some filtering and/or validation and return the results to the presentation layer. So can anyone clarify the differences between the two? Or am i missing the mark in my assesment?

I am working with EF, MVC 3 and VBNET, FYI

Answer

Shiraz Bhaiji picture Shiraz Bhaiji · Oct 12, 2011

In our projects we often have the following structure:

Service layer:

  • Publishes the Service Endpoint (this could be your MVC web page, or a WCF endpoint)
  • Does a security check
  • Maps data from contract data transfer objects to business objects
  • Calls functionality in the business layer

Business layer

  • Contains business logic
  • Accesses the data layer (this could be your entity framework data model)