From 898cdedb5b0b020a0f7b093898768de3cd006adc Mon Sep 17 00:00:00 2001 From: Ebbe Knudsen Date: Tue, 19 Nov 2024 13:48:55 +0100 Subject: [PATCH] Update client service bus options --- .../DependencyInjection/ClientExtensions.cs | 11 +++-- ...ProcessManagerServiceBusClientsOptions.cs} | 4 +- ...ocessManagerServiceBusOptionsExtensions.cs | 40 ------------------- .../V1/RequestCalculatedDataClientV1.cs | 2 +- 4 files changed, 10 insertions(+), 47 deletions(-) rename source/ProcessManager.Client/Extensions/Options/{ProcessManagerServiceBusOptions.cs => ProcessManagerServiceBusClientsOptions.cs} (89%) delete mode 100644 source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusOptionsExtensions.cs diff --git a/source/ProcessManager.Client/Extensions/DependencyInjection/ClientExtensions.cs b/source/ProcessManager.Client/Extensions/DependencyInjection/ClientExtensions.cs index bb80f4188c..ae702bd620 100644 --- a/source/ProcessManager.Client/Extensions/DependencyInjection/ClientExtensions.cs +++ b/source/ProcessManager.Client/Extensions/DependencyInjection/ClientExtensions.cs @@ -61,11 +61,14 @@ public static IServiceCollection AddProcessManagerHttpClients(this IServiceColle /// /// Register Process Manager RequestCalculatedData client for use in applications. - /// The application must register the by calling + /// The application must register the and contain configuration for /// public static IServiceCollection AddProcessManagerRequestCalculatedDataClient(this IServiceCollection services) { - services.AddProcessManagerServiceBusOptions(); + services + .AddOptions() + .BindConfiguration(ProcessManagerServiceBusClientsOptions.SectionName) + .ValidateDataAnnotations(); services.AddAzureClients( builder => @@ -73,14 +76,14 @@ public static IServiceCollection AddProcessManagerRequestCalculatedDataClient(th builder.AddClient( (_, _, provider) => { - var serviceBusOptions = provider.GetRequiredProcessManagerServiceBusOptions(); + var serviceBusOptions = provider.GetRequiredService>().Value; var serviceBusSender = provider .GetRequiredService() .CreateSender(serviceBusOptions.ProcessManagerTopic); return serviceBusSender; }) - .WithName(nameof(ProcessManagerServiceBusOptions.ProcessManagerTopic)); + .WithName(nameof(ProcessManagerServiceBusClientsOptions.ProcessManagerTopic)); }); services.AddScoped(); diff --git a/source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusOptions.cs b/source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusClientsOptions.cs similarity index 89% rename from source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusOptions.cs rename to source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusClientsOptions.cs index 4acfb500fa..72b90c9010 100644 --- a/source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusOptions.cs +++ b/source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusClientsOptions.cs @@ -20,9 +20,9 @@ namespace Energinet.DataHub.ProcessManager.Client.Extensions.Options; /// /// Options for configuration of Process Manager Service Bus clients using the Process Manager. /// -public class ProcessManagerServiceBusOptions +public class ProcessManagerServiceBusClientsOptions { - public const string SectionName = "ProcessManagerServiceBus"; + public const string SectionName = "ProcessManagerServiceBusClients"; /// /// Name of the topic which the Process Manager receives service bus messages on diff --git a/source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusOptionsExtensions.cs b/source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusOptionsExtensions.cs deleted file mode 100644 index dd19354a5a..0000000000 --- a/source/ProcessManager.Client/Extensions/Options/ProcessManagerServiceBusOptionsExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2020 Energinet DataHub A/S -// -// Licensed under the Apache License, Version 2.0 (the "License2"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; - -namespace Energinet.DataHub.ProcessManager.Client.Extensions.Options; - -public static class ProcessManagerServiceBusOptionsExtensions -{ - public static void AddProcessManagerServiceBusOptions(this IServiceCollection services) - { - services - .AddOptions() - .BindConfiguration(ProcessManagerServiceBusOptions.SectionName) - .ValidateDataAnnotations() - .ValidateOnStart(); - } - - /// - /// Get the registered in the service provider. - /// Throws an exception if the for hasn't been registered. - /// - public static ProcessManagerServiceBusOptions GetRequiredProcessManagerServiceBusOptions(this IServiceProvider provider) - { - var options = provider.GetRequiredService>(); - return options.Value; - } -} diff --git a/source/ProcessManager.Client/Processes/BRS_026_028/V1/RequestCalculatedDataClientV1.cs b/source/ProcessManager.Client/Processes/BRS_026_028/V1/RequestCalculatedDataClientV1.cs index 9d78207cd7..0365a0506b 100644 --- a/source/ProcessManager.Client/Processes/BRS_026_028/V1/RequestCalculatedDataClientV1.cs +++ b/source/ProcessManager.Client/Processes/BRS_026_028/V1/RequestCalculatedDataClientV1.cs @@ -27,7 +27,7 @@ namespace Energinet.DataHub.ProcessManager.Client.Processes.BRS_026_028.V1; public class RequestCalculatedDataClientV1( IAzureClientFactory serviceBusFactory) : IRequestCalculatedDataClientV1 { - private readonly ServiceBusSender _serviceBusSender = serviceBusFactory.CreateClient(nameof(ProcessManagerServiceBusOptions.ProcessManagerTopic)); + private readonly ServiceBusSender _serviceBusSender = serviceBusFactory.CreateClient(nameof(ProcessManagerServiceBusClientsOptions.ProcessManagerTopic)); public async Task RequestCalculatedEnergyTimeSeriesAsync(RequestCalculatedDataInputV1 input, CancellationToken cancellationToken) {