I am planning to use the repository pattern to call third party web service clients. What is the best way to use the factory pattern in this case. I was not able to add the code snippet initially. Looking for an elegant way to replace the if switch statement below.
public class LoanRepository<T> : ILoanRepository<T>
{
public async Task<T> GetByIdAsync(string loanNumber)
{
if (loanNumber.StartsWith("A"))
{
//Auto Loan
if (typeof(T) == typeof(Account))
{
// var client = new AutoAccountClient(new BasicHttpBinding(), new EndpointAddress(
new Uri("http://autourl/services")));
return new Account() { loanAmount = t.amt };
}
else if (typeof(T) == typeof(ContactInfo))
{
var client = new AutoContactClient(new BasicHttpBinding(), new EndpointAddress(
new Uri("http://autourl/services")));
return new ContactInfo() { consumerName = t.consumerName };
}
} else if (loanNumber.StartsWith("M"))
{
....
}
}
}
Aucun commentaire:
Enregistrer un commentaire