diff --git a/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionsCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionsCommand.cs index bfe57ff..2ed4b66 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionsCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionsCommand.cs @@ -1,4 +1,5 @@ using MediatR; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using ReC.Application.RecActions.Queries; @@ -12,7 +13,7 @@ public static class InvokeBatchRecActionsCommandExtensions => sender.Send(new InvokeBatchRecActionsCommand { ProfileId = profileId }, cancel); } -public class InvokeRecActionsCommandHandler(ISender sender, IHttpClientFactory clientFactory, ILogger? logger = null) : IRequestHandler +public class InvokeRecActionsCommandHandler(ISender sender, IServiceScopeFactory scopeFactory, IHttpClientFactory clientFactory, ILogger? logger = null) : IRequestHandler { public async Task Handle(InvokeBatchRecActionsCommand request, CancellationToken cancel) { @@ -27,7 +28,9 @@ public class InvokeRecActionsCommandHandler(ISender sender, IHttpClientFactory c await semaphore.WaitAsync(cancel); try { - await sender.Send(action.ToInvokeCommand(), cancel); + using var scope = scopeFactory.CreateScope(); + var sender = scope.ServiceProvider.GetRequiredService(); + await sender.Send(action.ToInvokeCommand(), cancel); } catch(Exception ex) {