Skip to content

Commit

Permalink
Resolve HttpClient in factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
boma96 committed Oct 13, 2024
1 parent f9e70aa commit 12e01e4
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/AdminService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ConductorSharp.Client.Service
{
public class AdminService(IHttpClientFactory httpClientFactory, string clientName) : IAdminService
public class AdminService(HttpClient client) : IAdminService
{
private readonly ConductorClient _client = new(httpClientFactory.CreateClient(clientName));
private readonly ConductorClient _client = new(client);

public async Task<string> QueueRunningWorkflowsForSweepAsync(string workflowId, CancellationToken cancellationToken = default) =>
await _client.RequeueSweepAsync(workflowId, cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace ConductorSharp.Client.Service
{
public class EventService(IHttpClientFactory httpClientFactory, string clientName) : IEventService
public class EventService(HttpClient client) : IEventService
{
private readonly ConductorClient _client = new(httpClientFactory.CreateClient(clientName));
private readonly ConductorClient _client = new(client);

public async Task<ICollection<EventHandler>> ListAsync(CancellationToken cancellationToken = default) =>
await _client.GetEventHandlersAsync(cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/ExternalPayloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace ConductorSharp.Client.Service
{
public class ExternalPayloadService(IHttpClientFactory httpClientFactory, string clientName) : IExternalPayloadService
public class ExternalPayloadService(HttpClient client) : IExternalPayloadService
{
private readonly ConductorClient _client = new(httpClientFactory.CreateClient(clientName));
private readonly ConductorClient _client = new(client);

public async Task<FileResponse> GetExternalStorageDataAsync(string externalPayloadPath, CancellationToken cancellationToken = default) =>
await _client.GetExternalStorageDataAsync(externalPayloadPath, cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/HealthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace ConductorSharp.Client.Service
{
public class HealthService(IHttpClientFactory httpClientFactory, string clientName) : IHealthService
public class HealthService(HttpClient client) : IHealthService
{
private readonly ConductorClient _client = new(httpClientFactory.CreateClient(clientName));
private readonly ConductorClient _client = new(client);

public async Task<HealthCheckStatus> CheckHealthAsync(CancellationToken cancellationToken = default) =>
await _client.DoCheckAsync(cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/MetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ConductorSharp.Client.Service
{
public class MetadataService(IHttpClientFactory httpClientFactory, string clientName) : IMetadataService
public class MetadataService(HttpClient client) : IMetadataService
{
private readonly ConductorClient _client = new(httpClientFactory.CreateClient(clientName));
private readonly ConductorClient _client = new(client);

public async Task<ICollection<WorkflowDef>> ListWorkflowsAsync(CancellationToken cancellationToken = default) =>
await _client.GetAllAsync(cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/QueueAdminService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace ConductorSharp.Client.Service;

public class QueueAdminService(IHttpClientFactory httpClientFactory, string clientName) : IQueueAdminService
public class QueueAdminService(HttpClient client) : IQueueAdminService
{
private readonly ConductorClient _client = new(httpClientFactory.CreateClient(clientName));
private readonly ConductorClient _client = new(client);

public async Task MarkWaitTaskCompletedAsync(
string workflowId,
Expand Down
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/TaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ConductorSharp.Client.Service
{
public class TaskService(IHttpClientFactory httpClientFactory, string clientName) : ITaskService
public class TaskService(HttpClient client) : ITaskService
{
private readonly ConductorClient _client = new(httpClientFactory.CreateClient(clientName));
private readonly ConductorClient _client = new(client);

public async Task<string> UpdateAsync(TaskResult updateRequest, CancellationToken cancellationToken = default) =>
await _client.UpdateTaskAsync(updateRequest, cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/WorkflowBulkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ConductorSharp.Client.Service;

public class WorkflowBulkService(IHttpClientFactory httpClientFactory, string clientName) : IWorkflowBulkService
public class WorkflowBulkService(HttpClient client) : IWorkflowBulkService
{
private readonly ConductorClient _client = new(httpClientFactory.CreateClient(clientName));
private readonly ConductorClient _client = new(client);

public async Task<BulkResponse> ResumeAsync(IEnumerable<string> workflowIds, CancellationToken cancellationToken = default) =>
await _client.ResumeWorkflow_1Async(workflowIds, cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/ConductorSharp.Client/Service/WorkflowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace ConductorSharp.Client.Service
{
public class WorkflowService(IHttpClientFactory httpClientFactory, string clientName) : IWorkflowService
public class WorkflowService(HttpClient client) : IWorkflowService
{
private readonly ConductorClient _client = new(httpClientFactory.CreateClient(clientName));
private readonly ConductorClient _client = new(client);

/// <summary>
/// Skips a given task from a current running workflow
Expand Down
27 changes: 18 additions & 9 deletions src/ConductorSharp.Engine/Extensions/ConductorSharpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,24 @@ public IConductorSharpBuilder AddAlternateClient(string baseUrl, string key, str
);
}

builder.AddKeyedTransient<IAdminService, AdminService>(key, ((sp, _) => new(sp.GetService<IHttpClientFactory>(), key)));
builder.AddKeyedTransient<IEventService, EventService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>(), key));
builder.AddKeyedTransient<IExternalPayloadService, ExternalPayloadService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>(), key));
builder.AddKeyedTransient<IQueueAdminService, QueueAdminService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>(), key));
builder.AddKeyedTransient<IWorkflowBulkService, WorkflowBulkService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>(), key));
builder.AddKeyedTransient<ITaskService, TaskService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>(), key));
builder.AddKeyedTransient<IHealthService, HealthService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>(), key));
builder.AddKeyedTransient<IMetadataService, MetadataService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>(), key));
builder.AddKeyedTransient<IWorkflowService, WorkflowService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>(), key));
builder.AddKeyedTransient<IAdminService, AdminService>(key, ((sp, _) => new(sp.GetService<IHttpClientFactory>().CreateClient(key))));
builder.AddKeyedTransient<IEventService, EventService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>().CreateClient(key)));
builder.AddKeyedTransient<IExternalPayloadService, ExternalPayloadService>(
key,
(sp, _) => new(sp.GetService<IHttpClientFactory>().CreateClient(key))
);
builder.AddKeyedTransient<IQueueAdminService, QueueAdminService>(
key,
(sp, _) => new(sp.GetService<IHttpClientFactory>().CreateClient(key))
);
builder.AddKeyedTransient<IWorkflowBulkService, WorkflowBulkService>(
key,
(sp, _) => new(sp.GetService<IHttpClientFactory>().CreateClient(key))
);
builder.AddKeyedTransient<ITaskService, TaskService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>().CreateClient(key)));
builder.AddKeyedTransient<IHealthService, HealthService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>().CreateClient(key)));
builder.AddKeyedTransient<IMetadataService, MetadataService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>().CreateClient(key)));
builder.AddKeyedTransient<IWorkflowService, WorkflowService>(key, (sp, _) => new(sp.GetService<IHttpClientFactory>().CreateClient(key)));

return this;
}
Expand Down
24 changes: 15 additions & 9 deletions src/ConductorSharp.Engine/Extensions/ContainerBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,21 @@ public static IConductorSharpBuilder AddConductorSharp(
);
}

builder.AddTransient<IAdminService, AdminService>(sp => new(sp.GetService<IHttpClientFactory>(), DefaultClientName));
builder.AddTransient<IEventService, EventService>(sp => new(sp.GetService<IHttpClientFactory>(), DefaultClientName));
builder.AddTransient<IExternalPayloadService, ExternalPayloadService>(sp => new(sp.GetService<IHttpClientFactory>(), DefaultClientName));
builder.AddTransient<IQueueAdminService, QueueAdminService>(sp => new(sp.GetService<IHttpClientFactory>(), DefaultClientName));
builder.AddTransient<IWorkflowBulkService, WorkflowBulkService>(sp => new(sp.GetService<IHttpClientFactory>(), DefaultClientName));
builder.AddTransient<ITaskService, TaskService>(sp => new(sp.GetService<IHttpClientFactory>(), DefaultClientName));
builder.AddTransient<IHealthService, HealthService>(sp => new(sp.GetService<IHttpClientFactory>(), DefaultClientName));
builder.AddTransient<IMetadataService, MetadataService>(sp => new(sp.GetService<IHttpClientFactory>(), DefaultClientName));
builder.AddTransient<IWorkflowService, WorkflowService>(sp => new(sp.GetService<IHttpClientFactory>(), DefaultClientName));
builder.AddTransient<IAdminService, AdminService>(sp => new(sp.GetService<IHttpClientFactory>().CreateClient(DefaultClientName)));
builder.AddTransient<IEventService, EventService>(sp => new(sp.GetService<IHttpClientFactory>().CreateClient(DefaultClientName)));
builder.AddTransient<IExternalPayloadService, ExternalPayloadService>(
sp => new(sp.GetService<IHttpClientFactory>().CreateClient(DefaultClientName))
);
builder.AddTransient<IQueueAdminService, QueueAdminService>(
sp => new(sp.GetService<IHttpClientFactory>().CreateClient(DefaultClientName))
);
builder.AddTransient<IWorkflowBulkService, WorkflowBulkService>(
sp => new(sp.GetService<IHttpClientFactory>().CreateClient(DefaultClientName))
);
builder.AddTransient<ITaskService, TaskService>(sp => new(sp.GetService<IHttpClientFactory>().CreateClient(DefaultClientName)));
builder.AddTransient<IHealthService, HealthService>(sp => new(sp.GetService<IHttpClientFactory>().CreateClient(DefaultClientName)));
builder.AddTransient<IMetadataService, MetadataService>(sp => new(sp.GetService<IHttpClientFactory>().CreateClient(DefaultClientName)));
builder.AddTransient<IWorkflowService, WorkflowService>(sp => new(sp.GetService<IHttpClientFactory>().CreateClient(DefaultClientName)));

builder.AddSingleton(new BuildConfiguration());
builder.AddSingleton<WorkflowBuildItemRegistry>();
Expand Down

0 comments on commit 12e01e4

Please sign in to comment.