|
2 | 2 | using System.Text.Json.Serialization;
|
3 | 3 | using Elsa.Api.Client.Contracts;
|
4 | 4 | using Elsa.Api.Client.Converters;
|
| 5 | +using Elsa.Api.Client.HttpMessageHandlers; |
5 | 6 | using Elsa.Api.Client.Options;
|
6 | 7 | using Elsa.Api.Client.Resources.ActivityDescriptorOptions.Contracts;
|
7 | 8 | using Elsa.Api.Client.Resources.ActivityDescriptors.Contracts;
|
@@ -31,6 +32,31 @@ namespace Elsa.Api.Client.Extensions;
|
31 | 32 | [PublicAPI]
|
32 | 33 | public static class DependencyInjectionExtensions
|
33 | 34 | {
|
| 35 | + /// <summary> |
| 36 | + /// Adds the Elsa client to the service collection. |
| 37 | + /// </summary> |
| 38 | + /// <param name="services">The service collection.</param> |
| 39 | + /// <param name="baseAddress">The base address of the Elsa API.</param> |
| 40 | + /// <param name="apiKey">The API key to use for authentication.</param> |
| 41 | + /// <param name="configureOptions">An optional delegate that can be used to configure the client options.</param> |
| 42 | + /// <param name="configureBuilderOptions">An optional delegate that can be used to configure the client builder options.</param> |
| 43 | + public static IServiceCollection AddElsaClient(this IServiceCollection services, Uri baseAddress, string apiKey, Action<ElsaClientOptions>? configureOptions = default, Action<ElsaClientBuilderOptions>? configureBuilderOptions = default) |
| 44 | + { |
| 45 | + services.AddScoped<ApiKeyHttpMessageHandler>(); |
| 46 | + return services.AddElsaClient( |
| 47 | + options => |
| 48 | + { |
| 49 | + options.BaseAddress = baseAddress; |
| 50 | + options.ApiKey = apiKey; |
| 51 | + configureOptions?.Invoke(options); |
| 52 | + }, |
| 53 | + configureBuilderOptions: options => |
| 54 | + { |
| 55 | + options.ConfigureHttpClientBuilder = builder => builder.AddHttpMessageHandler<ApiKeyHttpMessageHandler>(); |
| 56 | + configureBuilderOptions?.Invoke(options); |
| 57 | + }); |
| 58 | + } |
| 59 | + |
34 | 60 | /// <summary>
|
35 | 61 | /// Adds the Elsa client to the service collection.
|
36 | 62 | /// </summary>
|
|
0 commit comments