// // StatefulPreExecutionEvent.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using NosSmooth.Core.Client; using NosSmooth.Core.Commands; using NosSmooth.Core.Packets; using NosSmooth.Packets; using Remora.Results; namespace NosSmooth.Core.Stateful; /// /// Event that injects stateful entities into the scope. /// internal class StatefulPreExecutionEvent : IPreExecutionEvent, IPreCommandExecutionEvent { private readonly StatefulInjector _injector; /// /// Initializes a new instance of the class. /// /// The injector. public StatefulPreExecutionEvent(StatefulInjector injector) { _injector = injector; } /// public Task ExecuteBeforeExecutionAsync (INostaleClient client, PacketEventArgs packetArgs, CancellationToken ct = default) where TPacket : IPacket { _injector.Client = client; return Task.FromResult(Result.FromSuccess()); } /// public Task ExecuteBeforeCommandAsync(INostaleClient client, TCommand command, CancellationToken ct = default) where TCommand : ICommand { _injector.Client = client; return Task.FromResult(Result.FromSuccess()); } }