|
18 | 18 | using Gotenberg.Sharp.API.Client.Domain.Settings; |
19 | 19 | using Gotenberg.Sharp.API.Client.Infrastructure.Pipeline; |
20 | 20 |
|
21 | | - |
22 | | - |
23 | 21 | using Microsoft.Extensions.DependencyInjection; |
24 | 22 | using Microsoft.Extensions.Options; |
25 | 23 |
|
26 | 24 | namespace Gotenberg.Sharp.API.Client.Extensions; |
27 | 25 |
|
28 | 26 | /// <summary> |
29 | | -/// Extension methods for registering GotenbergSharpClient with dependency injection. |
| 27 | +/// Extension methods for registering GotenbergSharpClient with dependency injection. |
30 | 28 | /// </summary> |
31 | 29 | public static class TypedClientServiceCollectionExtensions |
32 | 30 | { |
33 | 31 | /// <summary> |
34 | | - /// Registers GotenbergSharpClient with dependency injection using configured options. |
35 | | - /// Configure options via appsettings.json or by calling services.Configure<GotenbergSharpClientOptions>(). |
| 32 | + /// Registers GotenbergSharpClient with dependency injection using configured options. |
| 33 | + /// Configure options via appsettings.json or by calling services.Configure<GotenbergSharpClientOptions>(). |
36 | 34 | /// </summary> |
37 | 35 | /// <param name="services">The service collection.</param> |
38 | 36 | /// <returns>An IHttpClientBuilder for further configuration.</returns> |
39 | 37 | /// <exception cref="ArgumentNullException">Thrown when services is null.</exception> |
40 | 38 | /// <remarks> |
41 | | - /// This method configures the HttpClient with automatic compression, retry policies, and basic authentication if credentials are provided. |
42 | | - /// Options should be configured in the "GotenbergSharpClient" section of appsettings.json or programmatically. |
| 39 | + /// This method configures the HttpClient with automatic compression, retry policies, and basic authentication if |
| 40 | + /// credentials are provided. |
| 41 | + /// Options should be configured in the "GotenbergSharpClient" section of appsettings.json or programmatically. |
43 | 42 | /// </remarks> |
44 | 43 | public static IHttpClientBuilder AddGotenbergSharpClient( |
45 | 44 | this IServiceCollection services) |
46 | 45 | { |
47 | | - if (services == null) throw new ArgumentNullException(nameof(services)); |
48 | | - |
49 | | - return services.AddGotenbergSharpClient( |
50 | | - (sp, client) => |
51 | | - { |
52 | | - var ops = GetOptions(sp); |
53 | | - client.Timeout = ops.TimeOut; |
54 | | - client.BaseAddress = ops.ServiceUrl; |
55 | | - }); |
| 46 | + if (services == null) |
| 47 | + { |
| 48 | + throw new ArgumentNullException(nameof(services)); |
| 49 | + } |
| 50 | + |
| 51 | + return services.AddGotenbergSharpClient((sp, client) => |
| 52 | + { |
| 53 | + var ops = GetOptions(sp); |
| 54 | + client.Timeout = ops.TimeOut; |
| 55 | + client.BaseAddress = ops.ServiceUrl; |
| 56 | + }); |
56 | 57 | } |
57 | 58 |
|
58 | | - |
59 | 59 | /// <summary> |
60 | | - /// Registers GotenbergSharpClient with dependency injection using a custom HttpClient configuration. |
| 60 | + /// Registers GotenbergSharpClient with dependency injection using a custom HttpClient configuration. |
61 | 61 | /// </summary> |
62 | 62 | /// <param name="services">The service collection.</param> |
63 | 63 | /// <param name="configureClient">Action to configure the HttpClient instance.</param> |
64 | 64 | /// <returns>An IHttpClientBuilder for further configuration.</returns> |
65 | 65 | /// <exception cref="ArgumentNullException">Thrown when configureClient is null.</exception> |
66 | 66 | /// <remarks> |
67 | | - /// This overload allows full control over HttpClient configuration. The client is configured with |
68 | | - /// automatic compression, timeout handling, and exponential backoff retry policies. |
| 67 | + /// This overload allows full control over HttpClient configuration. The client is configured with |
| 68 | + /// automatic compression, timeout handling, and exponential backoff retry policies. |
69 | 69 | /// </remarks> |
70 | 70 | public static IHttpClientBuilder AddGotenbergSharpClient( |
71 | 71 | this IServiceCollection services, |
72 | 72 | Action<IServiceProvider, HttpClient> configureClient) |
73 | 73 | { |
74 | | - if (configureClient == null) throw new ArgumentNullException(nameof(configureClient)); |
| 74 | + if (configureClient == null) |
| 75 | + { |
| 76 | + throw new ArgumentNullException(nameof(configureClient)); |
| 77 | + } |
75 | 78 |
|
76 | 79 | var builder = services |
77 | 80 | .AddHttpClient(nameof(GotenbergSharpClient), configureClient) |
78 | 81 | .AddTypedClient<GotenbergSharpClient>() |
79 | | - .ConfigurePrimaryHttpMessageHandler( |
80 | | - () => new TimeoutHandler( |
81 | | - new HttpClientHandler |
82 | | - { |
83 | | - AutomaticDecompression = DecompressionMethods.GZip |
84 | | - | DecompressionMethods.Deflate |
85 | | - })) |
| 82 | + .ConfigurePrimaryHttpMessageHandler(() => new TimeoutHandler( |
| 83 | + new HttpClientHandler |
| 84 | + { |
| 85 | + AutomaticDecompression = DecompressionMethods.GZip |
| 86 | + | DecompressionMethods.Deflate |
| 87 | + })) |
86 | 88 | .AddHttpMessageHandler(sp => |
87 | 89 | { |
88 | 90 | var ops = GetOptions(sp); |
|
0 commit comments