Skip to content

Instantly share code, notes, and snippets.

@DavidBasarab
Created March 5, 2019 11:38
Show Gist options
  • Select an option

  • Save DavidBasarab/b3374565512e473e572e70faff86411e to your computer and use it in GitHub Desktop.

Select an option

Save DavidBasarab/b3374565512e473e572e70faff86411e to your computer and use it in GitHub Desktop.
WebCallerAbstractIdea.cs
public class MyWebCaller : WebCaller
{
private static readonly HttpClient client = CreateHttpClient();
public static HttpClient CreateHttpClient()
{
var specialClient = new HttpClient();
specialClient.DefaultRequestHeaders.ExpectContinue = false;
return specialClient;
}
public override HttpClient Client => client;
}
public class NormalWebCaller : WebCaller
{
// Keep this static to not change
private static readonly HttpClient client = new HttpClient();
public override HttpClient Client => client;
}
public abstract class WebCaller
{
public abstract HttpClient Client { get; }
public void Post(string url) => SendRequest(url);
protected void SendRequest(string url)
{
var someMessage = new HttpRequestMessage();
// Use the Abstract property
Client.SendAsync(someMessage);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment