开发者

Why are Data Access Layer built with Service AND DataProvider?

开发者 https://www.devze.com 2023-01-07 14:39 出处:网络
Hallo, Why do I need 2 classes to get my data? Why is a DataPr开发者_开发技巧ovider class not enough, if the Service does actually nothing except call the method in the DataProvider ?

Hallo,

Why do I need 2 classes to get my data? Why is a DataPr开发者_开发技巧ovider 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);

}


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();
 }
0

精彩评论

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