private static void ApplyGlobalBeforeHook(IApplicationBuilder builder, BotwinOptions options) { if (options?.Before != null) { builder.Use(async(ctx, next) => { var carryOn = await options.Before(ctx); //TODO Check if return Task.CompletedTask will it continue if (carryOn) { await next(); } }); } }
private static void ApplyGlobalBeforeHook(IApplicationBuilder builder, BotwinOptions options) { if (options?.Before != null) { builder.Use(async(ctx, next) => { var loggerFactory = ctx.RequestServices.GetService <ILoggerFactory>(); var logger = loggerFactory.CreateLogger("Botwin.GlobalBeforeHook"); logger.LogTrace("Executing global before hook"); var carryOn = await options.Before(ctx); if (carryOn) { logger.LogTrace("Executing next handler after global before hook"); await next(); } }); } }