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); };
public static TaskMiddleware <TContext> Compose <TContext>( this TaskMiddleware <TContext> middleware, params TaskMiddleware <TContext>[] middlewares) => middleware.Singleton().Concat(middlewares).Compose();
public static TaskMiddlewareFunc <TContext> Combine <TContext>( this TaskMiddleware <TContext> middleware, SimpleTaskMiddlewareFunc <TContext> func) => (context, ct) => middleware(context, (c, _) => func(c), ct);
public static TaskMiddlewareFunc <TContext> Combine <TContext>( this TaskMiddleware <TContext> middleware, TaskMiddlewareFunc <TContext> func) => (context, ct) => middleware(context, func, ct);