Add transaction support between services

This commit is contained in:
2025-10-27 18:09:09 +09:00
parent 6b3733001a
commit 9e526c54fa
11 changed files with 75 additions and 44 deletions

View File

@ -3,10 +3,10 @@ using Hcs.WebApp.Data.Hcs;
namespace Hcs.WebApp.BackgroundServices.OperationExecutors
{
public abstract class ExecutorBase(IClient client, IServiceScopeFactory scopeFactory, Operation operation) : IExecutor
public abstract class ExecutorBase(IClient client, IServiceScope scope, Operation operation) : IExecutor
{
protected readonly IClient client = client;
protected readonly IServiceScopeFactory scopeFactory = scopeFactory;
protected readonly IServiceScope scope = scope;
protected readonly Operation operation = operation;
public abstract Task<string> ExecuteAsync(CancellationToken cancellationToken);

View File

@ -4,16 +4,14 @@ using Hcs.WebApp.Data.Hcs;
namespace Hcs.WebApp.BackgroundServices.OperationExecutors
{
public class ExecutorFactory(IServiceScopeFactory scopeFactory)
public class ExecutorFactory
{
protected readonly IServiceScopeFactory scopeFactory = scopeFactory;
public IExecutor CreateExecutor(IClient client, Operation operation)
public IExecutor CreateExecutor(IServiceScope scope, IClient client, Operation operation)
{
switch (operation.Type)
{
case Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1:
return new ExportNsiItemExecutor_15_7_0_1(client, scopeFactory, operation);
return new ExportNsiItemExecutor_15_7_0_1(client, scope, operation);
}
throw new NotImplementedException();

View File

@ -5,13 +5,12 @@ using Hcs.WebApp.Services;
namespace Hcs.WebApp.BackgroundServices.OperationExecutors.NsiCommon
{
public class ExportNsiItemExecutor_15_7_0_1(IClient client, IServiceScopeFactory scopeFactory, Operation operation) : ExecutorBase(client, scopeFactory, operation)
public class ExportNsiItemExecutor_15_7_0_1(IClient client, IServiceScope scope, Operation operation) : ExecutorBase(client, scope, operation)
{
public override async Task<string> ExecuteAsync(CancellationToken cancellationToken)
{
using var scope = scopeFactory.CreateScope();
var registryService = scope.ServiceProvider.GetRequiredService<RegistryService>();
var registry = await registryService.GetRegistryByOperationId(operation.Id);
var registry = await registryService.GetRegistryByOperationIdAsync(operation.Id);
return await client.NsiCommon.RequestExportNsiItemAsync(registry.Number, ListGroup.NSI, cancellationToken);
}
}