/// <summary> /// Chains instances of <see cref="MiddlewareBase{TContext, TOut}"/> together using /// the given inner as the inner middleware. /// </summary> /// <param name="inner">The innermost instance of <see cref="MiddlewareBase{TContext, TOut}"/>.</param> /// <param name="middleware">The instances of <see cref="MiddlewareBase{TContext, TOut}"/> to add to the /// returned composite <see cref="MiddlewareBase{TContext, TOut}"/>.</param> /// <returns>A composite <see cref="MiddlewareBase{TContext, TOut}"/>.</returns> public static MiddlewareBase <TIn, TOut> WithAsync <TIn, TOut>( this MiddlewareBase <TIn, TOut> inner, params Func <MiddlewareBase <TIn, TOut>, MiddlewareBase <TIn, TOut> >[] middleware) { if (inner == null) { throw new ArgumentNullException(nameof(inner)); } if (middleware == null) { throw new ArgumentNullException(nameof(middleware)); } if (middleware.Any(x => x == null)) { throw new ArgumentException("All provided middlewares should be non-null", nameof(middleware)); } var policy = inner; foreach (var m in middleware) { policy = m(policy); } return(policy); }
public MiddlewareBase <TContext, TOut> WithNext(MiddlewareBase <TContext, TOut> next) { _next = next; return(this); }
public MiddlewareBase(MiddlewareBase <TContext, TOut> next = null) { _next = next; }