using Elsa.Mediator.Contexts;
using Elsa.Mediator.Contracts;
using Elsa.Mediator.Middleware.Command;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Mediator.CommandStrategies;
///
/// Invokes command handlers in the background and does not wait for the result.
///
public class BackgroundStrategy : ICommandStrategy
{
///
public async Task ExecuteAsync(CommandStrategyContext context)
{
var commandsChannel = context.ServiceProvider.GetRequiredService();
var commandContext = context.CommandContext;
var queuedContext = new CommandContext(
commandContext.Command,
CommandStrategy.Default,
commandContext.ResultType,
commandContext.Headers,
commandContext.ServiceProvider,
CancellationToken.None);
await commandsChannel.Writer.WriteAsync(queuedContext, context.CancellationToken);
return default!;
}
}