Hello,
I’m using the repository pattern to make call from my WPF application to a webservice using IServiceClient… My repositories inherits from a base class and all the methods are in the form
public Task<IList<Institute>> GetInstitutesAsync()
{
var client = GetServiceStackClient();
var request = new InstituteRequest();
return client.PostAsync(request);
}
public Task<IList<Status>> GetStatusAsync()
{
var client = GetServiceStackClient();
var request = new StatusRequest();
return client.PostAsync(request);
}
I’ve created a generic method that wraps the Servicestack creation and the PostAsync so I can call the methods in the form
public Task<IList<Portfolio>> GetPortfoliosAsync(string username)
{
var request = new PortfolioRequest
{
UserName = username
};
return Get<IList<Portfolio>, PortfolioRequest>(request);
}
And the generic method is defined inside a DefaultRepositoryBase as
public class DefaultRepositoryBase : RepositoryBase
{
private static IServiceClient GetServiceStackClient(string path = "")
{
var defaultServerSettings = ServiceLocator.Default.ResolveType<ITesoreriaServerSettings>();
return defaultServerSettings.GetServiceStackClient(path);
}
internal static Task<TResponse> Get<TResponse, TRequest>(TRequest request)
{
var client = GetServiceStackClient();
return client.PostAsync<TResponse>(request);
}
}
I was wondering how the PostAsync can infers the types while I can’t (so I’ve to write the <TResponse,TRequest>
Is there a way I can avoid to write them?
Thanks
Paolo