Update API client

This commit is contained in:
Sipke Schoorstra 2023-07-31 22:37:57 +02:00
parent 10a71d3049
commit c429fe6fcc
2 changed files with 7 additions and 1 deletions

View file

@ -32,7 +32,7 @@ public static class DependencyInjectionExtensions
public static IServiceCollection AddElsaClient(this IServiceCollection services, Action<ElsaClientOptions> configureOptions)
{
services.Configure(configureOptions);
services.AddSingleton<IElsaClient, ElsaClient>();
services.AddScoped<IElsaClient, ElsaClient>();
services.AddActivityTypeService();
services.AddApi<IWorkflowDefinitionsApi>(CreateRefitSettings);
@ -71,6 +71,7 @@ public static class DependencyInjectionExtensions
{
var options = serviceProvider.GetRequiredService<IOptions<ElsaClientOptions>>().Value;
httpClient.BaseAddress = options.BaseAddress;
options.ConfigureHttpClient?.Invoke(httpClient);
}
private static RefitSettings CreateRefitSettings(IServiceProvider serviceProvider)

View file

@ -14,4 +14,9 @@ public class ElsaClientOptions
/// Gets or sets the API key to use when authenticating with the Elsa server.
/// </summary>
public string ApiKey { get; set; } = default!;
/// <summary>
/// Gets or sets a delegate that can be used to configure the HTTP client.
/// </summary>
public Action<HttpClient>? ConfigureHttpClient { get; set; }
}