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
- SavePost()
- SaveTags()
while service layer just does one
AddPost()
{
SavePost();
SaveTags();
}
精彩评论