public ValueTask <ICommandResult> ExecuteCallbacksAsync( CommandMiddleware final, CommandContext context, CancellationToken cancellationToken) { return(ExecuteNextAsync(_middleware, 0, context, cancellationToken, final));
public McConnection(McConnectionContext ctx) { this.ctx = ctx; var stateChange = new StateUpdateMiddleware(null); var command = new CommandMiddleware(stateChange.Invoke); var compression = new CompressionMiddleware(command.Invoke); connectionMiddleware = new MessageBuilderMiddleware(compression.Invoke); }
private static async ValueTask <ICommandResult> TestMiddlewareAsync( CommandMiddleware next, CommandContext context, CancellationToken cancellationToken) { var logger = context.Services .GetRequiredService <ILoggerFactory>() .CreateLogger(typeof(Program).Name); logger.LogInformation("Hello world from middleware!"); return(await next()); }
static async ValueTask <ICommandResult> ExecuteNextAsync( List <Middleware> middleware, int pos, CommandContext context, CancellationToken token, CommandMiddleware final) { return(pos >= middleware.Count ? await final() : await middleware[pos]( () => ExecuteNextAsync(middleware, pos + 1, context, token, final), context, token)); }