Пример #1
0
        public static TaskMiddleware <TContext> Choose <TContext>(
            this IEnumerable <TaskMiddleware <TContext> > choices,
            Func <TContext, Task <bool> > wasChosen,
            TaskMiddleware <TContext> defaultAction) =>
        async(context, next, ct) =>
        {
            foreach (var middleware in choices)
            {
                await middleware(context, next, ct);

                if (await wasChosen(context))
                {
                    return;
                }
            }

            await defaultAction(context, next, ct);
        };
Пример #2
0
 public static TaskMiddleware <TContext> Compose <TContext>(
     this TaskMiddleware <TContext> middleware,
     params TaskMiddleware <TContext>[] middlewares) =>
 middleware.Singleton().Concat(middlewares).Compose();
Пример #3
0
 public static TaskMiddlewareFunc <TContext> Combine <TContext>(
     this TaskMiddleware <TContext> middleware,
     SimpleTaskMiddlewareFunc <TContext> func) =>
 (context, ct) => middleware(context, (c, _) => func(c), ct);
Пример #4
0
 public static TaskMiddlewareFunc <TContext> Combine <TContext>(
     this TaskMiddleware <TContext> middleware,
     TaskMiddlewareFunc <TContext> func) =>
 (context, ct) => middleware(context, func, ct);