diff --git a/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs b/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs index cf64528e2..bc08b314c 100644 --- a/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs +++ b/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs @@ -209,7 +209,7 @@ public class WorkflowRuntimeFeature : FeatureBase .AddScoped(ActivityExecutionLogStore) .AddScoped(WorkflowInboxStore) .AddScoped(WorkflowExecutionContextStore) - .AddSingleton(RunTaskDispatcher) + .AddScoped(RunTaskDispatcher) .AddSingleton(BackgroundActivityScheduler) .AddSingleton() .AddScoped() diff --git a/src/modules/Elsa.Workflows.Runtime/Services/BackgroundTaskDispatcher.cs b/src/modules/Elsa.Workflows.Runtime/Services/BackgroundTaskDispatcher.cs index a73edb92c..f2105bb3e 100644 --- a/src/modules/Elsa.Workflows.Runtime/Services/BackgroundTaskDispatcher.cs +++ b/src/modules/Elsa.Workflows.Runtime/Services/BackgroundTaskDispatcher.cs @@ -2,20 +2,17 @@ using Elsa.Mediator; using Elsa.Mediator.Contracts; using Elsa.Workflows.Runtime.Contracts; using Elsa.Workflows.Runtime.Notifications; -using Microsoft.Extensions.DependencyInjection; namespace Elsa.Workflows.Runtime.Services; /// /// Relies on the to publish the received request as a domain event from a background worker. /// -public class BackgroundTaskDispatcher(IServiceScopeFactory scopeFactory) : ITaskDispatcher +public class BackgroundTaskDispatcher(INotificationSender notificationSender) : ITaskDispatcher { /// public async Task DispatchAsync(RunTaskRequest request, CancellationToken cancellationToken = default) { - using var scope = scopeFactory.CreateScope(); - var notificationSender = scope.ServiceProvider.GetRequiredService(); await notificationSender.SendAsync(request, NotificationStrategy.Background, cancellationToken); } } \ No newline at end of file