示例#1
0
        public static AsyncMiddleware <TContext, TResult> Choose <TContext, TResult>(
            this IEnumerable <AsyncMiddleware <TContext, TResult> > choices,
            Func <TResult, TContext, Task <bool> > wasChosen,
            AsyncMiddleware <TContext, TResult> defaultAction) =>
        async(context, next, ct) =>
        {
            foreach (var middleware in choices)
            {
                var result = await middleware(context, next, ct);

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

            return(await defaultAction(context, next, ct));
        };
示例#2
0
 public static AsyncMiddleware <TContext, TResult> Compose <TContext, TResult>(
     this AsyncMiddleware <TContext, TResult> middleware,
     params AsyncMiddleware <TContext, TResult>[] middlewares) =>
 middleware.Singleton().Concat(middlewares).Compose();
示例#3
0
 public static AsyncMiddlewareFunc <TContext, TResult> Combine <TContext, TResult>(
     this AsyncMiddleware <TContext, TResult> middleware,
     SimpleAsyncMiddlewareFunc <TContext, TResult> func) =>
 (context, ct) => middleware(context, (c, _) => func(c), ct);
示例#4
0
 public static AsyncMiddlewareFunc <TContext, TResult> Combine <TContext, TResult>(
     this AsyncMiddleware <TContext, TResult> middleware,
     AsyncMiddlewareFunc <TContext, TResult> func) =>
 (context, ct) => middleware(context, func, ct);