| | | 1 | | using ArturRios.Util.WebApi.Handlers; |
| | | 2 | | using Microsoft.Extensions.DependencyInjection; |
| | | 3 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Util.WebApi.Extensions; |
| | | 6 | | |
| | | 7 | | /// <summary>Extension methods for wiring the library's handlers into named or typed <see cref="HttpClient"/>s.</summary |
| | | 8 | | public static class HttpClientBuilderExtensions |
| | | 9 | | { |
| | | 10 | | /// <param name="builder">The builder of the named or typed <see cref="HttpClient"/>.</param> |
| | | 11 | | extension(IHttpClientBuilder builder) |
| | | 12 | | { |
| | | 13 | | /// <summary>Adds <see cref="TracePropagationHandler"/> to the client's handler pipeline, so its outgoing reques |
| | | 14 | | /// carry the current W3C <c>traceparent</c>. Registers the handler with the container if it isn't already.</sum |
| | | 15 | | /// <returns>The same <paramref name="builder"/> instance, for chaining.</returns> |
| | | 16 | | public IHttpClientBuilder AddTracePropagation() |
| | | 17 | | { |
| | 1 | 18 | | builder.Services.TryAddTransient<TracePropagationHandler>(); |
| | | 19 | | |
| | 1 | 20 | | return builder.AddHttpMessageHandler<TracePropagationHandler>(); |
| | | 21 | | } |
| | | 22 | | } |
| | | 23 | | } |