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

@ -1,12 +1,24 @@
using Hcs.WebApp.Data.Hcs;
using Hcs.WebApp.Services;
namespace Hcs.WebApp.BackgroundServices.CampaignManagers
{
public class ExportRequiredRegistryElementsManager_15_7_0_1(OperationExecutionState state, IServiceScopeFactory scopeFactory, Campaign campaign) : ManagerBase(state, scopeFactory, campaign)
public class ExportRequiredRegistryElementsManager_15_7_0_1(IServiceScope scope, OperationExecutionState state, Campaign campaign) : ManagerBase(scope, state, campaign)
{
public override async Task StartAsync(CancellationToken cancellationToken)
{
// TODO
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
var registryService = scope.ServiceProvider.GetRequiredService<RegistryService>();
using var context = headquartersService.GetNewContext();
using var transaction = await context.Database.BeginTransactionAsync(cancellationToken);
try
{
// TODO
}
catch
{
throw;
}
}
}
}

View File

@ -2,10 +2,10 @@
namespace Hcs.WebApp.BackgroundServices.CampaignManagers
{
public abstract class ManagerBase(OperationExecutionState state, IServiceScopeFactory scopeFactory, Campaign campaign) : IManager
public abstract class ManagerBase(IServiceScope scope, OperationExecutionState state, Campaign campaign) : IManager
{
protected readonly IServiceScope scope = scope;
protected readonly OperationExecutionState state = state;
protected readonly IServiceScopeFactory scopeFactory = scopeFactory;
protected readonly Campaign campaign = campaign;
public IManager.ManagerState State { get; } = IManager.ManagerState.Created;

View File

@ -2,17 +2,16 @@
namespace Hcs.WebApp.BackgroundServices.CampaignManagers
{
public class ManagerFactory(OperationExecutionState state, IServiceScopeFactory scopeFactory)
public class ManagerFactory(OperationExecutionState state)
{
protected readonly OperationExecutionState state = state;
protected readonly IServiceScopeFactory scopeFactory = scopeFactory;
public IManager CreateManager(Campaign campaign)
public IManager CreateManager(IServiceScope scope, Campaign campaign)
{
switch (campaign.Type)
{
case Campaign.CampaignType.ExportRequiredRegistryElements_15_7_0_1:
return new ExportRequiredRegistryElementsManager_15_7_0_1(state, scopeFactory, campaign);
return new ExportRequiredRegistryElementsManager_15_7_0_1(scope, state, campaign);
}
throw new NotImplementedException();