Reputation: 1262
We currently have clients storing data in multiple data sources (MS SQL, Oracle, MS Access, Web Services, etc.).
We have created a framework to handle majority scenarios for MS SQL, Oracle, Access, however some clients are reluctant to provide direct DB access and hence give out only Web Services.
I am unable to come up with a generic solution to handle the 5% problem at hands to create something for the Web Services as the data source, along with others.
Can someone help me how to handle this kind of scenario.
-Naga
Upvotes: 0
Views: 256
Reputation: 9489
Treat your Web Service data source as no different than MS SQL or Oracle Data source. It is merely one additional concrete data store. Follow a pattern like this:
public interface IRepository
{
List<EmployeeModel> GetEmployees();
}
here EmployeeModel is a simple C# class, and not tied to Oracle or MS SQL or your web service.
public class SqlRepository : IRepository
{
public List<EmployeeModel> GetEmployees()
{
// get it from SQL using ADO.NET or Linq2Sql
// transform into EmployeeModel using Automapper/manual and return.
}
}
public class WebServiceRepository : IRepository
{
private readonly ProxyClient _proxy; // or helper
public List<EmployeeModel> GetEmployees()
{
// get it from the ASMX using Proxy Helpers with return type as data contracts.
// transform the data contracts into EmployeeModel using Automapper/manual and return.
}
}
Upvotes: 3
Reputation: 2684
I think one of the options is to use a Repository Pattern. Have a look at Repository pattern example at this: http://www.remondo.net/repository-pattern-example-csharp/
I hope this helps.
Upvotes: 0