-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @barruka, you are right that I did some tests just to see how some HTTP features affect the package size: Hello World Console - 1.2MB Console.WriteLine("Hello World"); HTTP Client - 5.1MB var client = new HttpClient();
var result = await client.GetStringAsync("https://jsonplaceholder.typicode.com/todos"); HTTP Client with var resilienceHandler = new ResilienceHandler(
new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddRetry(new HttpRetryStrategyOptions())
.Build());
resilienceHandler.InnerHandler = new HttpClientHandler();
var client = new HttpClient(resilienceHandler);
var result = await client.GetStringAsync("https://jsonplaceholder.typicode.com/todos"); HTTP Client with This sample illustrates how to create "standard resilience" without the DI. var standardOptions = new HttpStandardResilienceOptions();
var resilienceHandler = new ResilienceHandler(new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddRateLimiter(standardOptions.RateLimiter)
.AddTimeout(standardOptions.TotalRequestTimeout)
.AddRetry(standardOptions.Retry)
.AddCircuitBreaker(standardOptions.CircuitBreaker)
.AddTimeout(standardOptions.AttemptTimeout)
.Build());
resilienceHandler.InnerHandler = new HttpClientHandler();
var client = new HttpClient(resilienceHandler);
var result = await client.GetStringAsync("https://jsonplaceholder.typicode.com/todos"); HTTP Client with raw resilience - 5.745 MB var pipeline = new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddRetry(new Polly.Retry.RetryStrategyOptions<HttpResponseMessage>())
.Build();
using var message = new HttpRequestMessage(HttpMethod.Get, "https://jsonplaceholder.typicode.com/todos");
var client = new HttpClient();
await pipeline.ExecuteAsync(async token => await client.SendAsync(message, CancellationToken.None)); HTTP Client with standard resilience - 7.2 MB var services = new ServiceCollection();
services.AddHttpClient("my-endpoint").AddStandardResilienceHandler();
var client = services
.BuildServiceProvider()
.GetRequiredService<IHttpClientFactory>()
.CreateClient("my-endpoint");
var result = await client.GetStringAsync("https://jsonplaceholder.typicode.com/todos"); My <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.2.0" />
</ItemGroup>
</Project> And output executable was generated by calling FYI, we recommend |
Beta Was this translation helpful? Give feedback.
Hey @barruka, you are right that
Microsoft.Extensions.Http.Resilience
adds a bunch of dependencies. The good thing is that all these (up to the Polly itself) are trimming-friendly. So if you care about the publish size, I recommend to enable native AOT.I did some tests just to see how some HTTP features affect the package size:
Hello World Console - 1.2MB
HTTP Client - 5.1MB
HTTP Client with
ResilienceHandler
- 5.8MB