diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/ApplicationBuilderExtensions.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/ApplicationBuilderExtensions.cs index 7905b2557..f145c83e4 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/ApplicationBuilderExtensions.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/ApplicationBuilderExtensions.cs @@ -19,8 +19,7 @@ public static IHostApplicationBuilder AddWebhookDeliveryService(this IHostApplic { AddWebhookOptions(builder); - builder.Services.AddSingleton(); - WebhookSender.AddHttpClient(builder.Services); + WebhookSender.Register(builder.Services); builder.Services.AddSingleton(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookSender.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookSender.cs index f60aafc92..48574026f 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookSender.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookSender.cs @@ -54,7 +54,7 @@ public async Task SendMessageAsync(WebhookMessage message, CancellationToken can response.EnsureSuccessStatusCode(); } - public static void AddHttpClient(IServiceCollection services, Func? getPrimaryHandler = null) + public static void Register(IServiceCollection services, Func? getPrimaryHandler = null) { // We configure the options here manually rather than using the library-provided extension methods so that they don't 'bleed out' globally; // it's feasible we could want a different configuration of, say, AddContentDigestOptions for use elsewhere. @@ -108,8 +108,10 @@ IOptions GetMessageSigningOptions(IServiceProvider servic return new ECDsaP382Sha384SignatureProvider(cert, signingKeyId); }); + services.AddSingleton(); + var httpClientBuilder = services - .AddHttpClient(client => + .AddHttpClient(client => { client.Timeout = TimeSpan.FromSeconds(TimeoutSeconds); client.DefaultRequestHeaders.ExpectContinue = false; diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Services/Webhooks/WebhookSenderTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Services/Webhooks/WebhookSenderTests.cs index 02b7513a3..046ae98ca 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Services/Webhooks/WebhookSenderTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Services/Webhooks/WebhookSenderTests.cs @@ -134,10 +134,8 @@ public WebhookReceiver() ]; }); - builder.Services.AddSingleton(); - builder.Services.AddSingleton(); - WebhookSender.AddHttpClient(builder.Services, () => _server!.CreateHandler()); + WebhookSender.Register(builder.Services, () => _server!.CreateHandler()); builder.Services.Configure(options => { @@ -206,7 +204,7 @@ public WebhookReceiver() public WebhookMessageRecorder WebhookMessageRecorder => Services.GetRequiredService(); - public WebhookSender GetWebhookSender() => Services.GetRequiredService(); + public IWebhookSender GetWebhookSender() => Services.GetRequiredService(); public WebhookOptions GetWebhookOptions() => Services.GetRequiredService>().Value;