Beispiel #1
0
 Expression?IParameterMapper.MapParameter(MethodInfo taskMethodInfo, ParameterInfo parameterInfo, ParameterExpression contextParameter)
 {
     if (parameterInfo.ParameterType == typeof(T))
     {
         var typedResult = MapParameter(taskMethodInfo, parameterInfo);
         if (typedResult != default)
         {
             return(InlineLambdaVisitor.InlineLambda(
                        typedResult,
                        contextParameter
                        ));
         }
     }
     return(null);
 }
Beispiel #2
0
        public static Expression <Func <Task> > ApplyMiddlewares(IServiceProvider serviceProvider, ParameterExpression contextParameter, Expression <Func <Task> > expression)
        {
            var middlewares = serviceProvider.GetServices <IMiddleware>().ToArray();

            foreach (var middleware in middlewares.Reverse())
            {
                expression = Expression.Lambda <Func <Task> >(
                    InlineLambdaVisitor.InlineLambda <Func <IMiddleware, ITaskContext, Func <Task>, Task> >(
                        (middleware, context, next) => middleware.ExecuteAsync(context, next),
                        Expression.Constant(middleware),
                        contextParameter,
                        expression
                        )
                    );
            }
            return(expression);
        }