Created
March 5, 2019 11:38
-
-
Save DavidBasarab/b3374565512e473e572e70faff86411e to your computer and use it in GitHub Desktop.
WebCallerAbstractIdea.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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