Skip to content

Commit

Permalink
Update http extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ebbeknudsen committed Nov 14, 2024
1 parent 2b94889 commit 853eab8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Energinet.DataHub.ProcessManager.Client.Processes.BRS_026_028.V1;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

Expand Down Expand Up @@ -59,20 +60,27 @@ public static IServiceCollection AddProcessManagerHttpClients(this IServiceColle
}

/// <summary>
/// Register Process Manager Service Bus clients for use in applications.
/// Register Process Manager RequestCalculatedData client for use in applications.
/// <remarks>The application must register the <see cref="ServiceBusClient"/> by calling </remarks>
/// </summary>
public static IServiceCollection AddProcessManagerServiceBusClients(this IServiceCollection services)
public static IServiceCollection AddProcessManagerRequestCalculatedDataClient(this IServiceCollection services, IConfiguration configuration)
{
services.AddProcessManagerServiceBusOptions();

services.AddAzureClients(
builder =>
{
builder.AddClient<ServiceBusSender, ServiceBusClientOptions>(
(_, _, provider) =>
provider
.GetRequiredService<ServiceBusClient>()
.CreateSender(nameof(ProcessManagerServiceBusClientsOptions.ProcessManagerTopic)))
.WithName(nameof(ProcessManagerServiceBusClientsOptions.ProcessManagerTopic));
(_, _, provider) =>
{
var serviceBusOptions = provider.GetRequiredProcessManagerServiceBusOptions();
var serviceBusSender = provider
.GetRequiredService<ServiceBusClient>()
.CreateSender(serviceBusOptions.ProcessManagerTopic);

return serviceBusSender;
})
.WithName(nameof(ProcessManagerServiceBusOptions.ProcessManagerTopic));
});

services.AddScoped<IRequestCalculatedDataClientV1, RequestCalculatedDataClientV1>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 Energinet.DataHub.ProcessManager.Client.Extensions.Options;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace Energinet.DataHub.ProcessManager.Client.Extensions.DependencyInjection;

public static class ProcessManagerServiceBusOptionsExtensions
{
public static void AddProcessManagerServiceBusOptions(this IServiceCollection services)
{
services
.AddOptions<ProcessManagerServiceBusOptions>()
.BindConfiguration(ProcessManagerServiceBusOptions.SectionName)
.ValidateDataAnnotations()
.ValidateOnStart();
}

public static ProcessManagerServiceBusOptions GetRequiredProcessManagerServiceBusOptions(this IServiceProvider provider)
{
var options = provider.GetRequiredService<IOptions<ProcessManagerServiceBusOptions>>();
return options.Value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
// limitations under the License.

using System.ComponentModel.DataAnnotations;
using Microsoft.Extensions.Configuration;

namespace Energinet.DataHub.ProcessManager.Client.Extensions.Options;

/// <summary>
/// Options for the configuration of Process Manager Service Bus clients using the Process Manager.
/// Options for configuration of Process Manager Service Bus clients using the Process Manager.
/// </summary>
public class ProcessManagerServiceBusClientsOptions
public class ProcessManagerServiceBusOptions
{
public const string SectionName = "ProcessManagerServiceBusClients";
public const string SectionName = "ProcessManagerServiceBus";

/// <summary>
/// Name of the topic which the Process Manager receives service bus messages on
Expand Down

0 comments on commit 853eab8

Please sign in to comment.