Пример #1
0
        private static void ApplyGlobalBeforeHook(IApplicationBuilder builder, CarterOptions options, ILogger logger)
        {
            if (options?.Before != null)
            {
                builder.Use(async(ctx, next) =>
                {
                    logger.LogDebug("Executing global before hook");

                    var carryOn = await options.Before(ctx);
                    if (carryOn)
                    {
                        logger.LogDebug("Executing next handler after global before hook");
                        await next();
                    }
                });
            }
        }
Пример #2
0
        private static void ApplyGlobalBeforeHook(IApplicationBuilder builder, CarterOptions options)
        {
            if (options?.Before != null)
            {
                builder.Use(async(ctx, next) =>
                {
                    var loggerFactory = ctx.RequestServices.GetService <ILoggerFactory>();
                    var logger        = loggerFactory.CreateLogger("Carter.GlobalBeforeHook");
                    logger.LogDebug("Executing global before hook");

                    var carryOn = await options.Before(ctx);
                    if (carryOn)
                    {
                        logger.LogDebug("Executing next handler after global before hook");
                        await next();
                    }
                });
            }
        }