msfanboy
msfanboy

Reputation: 5291

Why are Data Access Layer built with Service AND DataProvider?

Hallo,

Why do I need 2 classes to get my data? Why is a DataProvider class not enough, if the Service does actually nothing except call the method in the DataProvider ?

interface ICustomerDataProvider
inferface ICustomerService

class CustomerDataProvider : ICustomerDataProvider
{
    // Do Sql queries here
    // return sql data and write all DataReader data into customer objects....

   public  IEnumerable<Customer> GetCustomers()
 {
    return ...
 }

}

class CustomerService : ICustomerService
{
    public IEnumerable<Customer> GetCustomers()
  {
       return _customerDataProvider.GetCustomers();
  }    
}

class BillingViewModel
{

  _customerService = Service.Resolve<ICustomer>();

 IEnumerable<Customer> customers = _customerService.GetCustomers();

  Customers = new ObservableCollection<Customer>(customers);

}

Upvotes: 0

Views: 337

Answers (1)

fengd
fengd

Reputation: 7579

if your service layer just call methods in your data providers, it means you have some problem in your design.

Data Providers are used to pull and push data. It takes small actions.

Service Layer performs "big actions", which composites small actions.

Take saving a blog post as an example: Data Providers do these seperatly

  1. SavePost()
  2. SaveTags()

while service layer just does one

 AddPost()
 {
     SavePost();
     SaveTags();
 }

Upvotes: 1

Related Questions