@@ -95,7 +95,6 @@ public static IApplicationBuilder UseMiddleware(this IApplicationBuilder app, Ty
95
95
96
96
private static Func < T , HttpContext , IServiceProvider , Task > Compile < T > ( MethodInfo methodinfo , ParameterInfo [ ] parameters )
97
97
{
98
-
99
98
// If we call something like
100
99
//
101
100
// public class Middleware
@@ -122,17 +121,6 @@ private static Func<T, HttpContext, IServiceProvider, Task> Compile<T>(MethodInf
122
121
// return ((Middleware)instance).Invoke(httpContext, (ILoggerFactory)UseMiddlewareExtensions.GetService(provider, typeof(ILoggerFactory));
123
122
// }
124
123
125
- // context =>
126
- // {
127
- // var serviceProvider = context.RequestServices ?? applicationServices;
128
- // if (serviceProvider == null)
129
- // {
130
- // throw new InvalidOperationException(Resources.FormatException_UseMiddlewareIServiceProviderNotAvailable(nameof(IServiceProvider)));
131
- // }
132
- //
133
- // return Invoke(httpContext, serviceProvider);
134
- // }
135
-
136
124
var middleware = typeof ( T ) ;
137
125
138
126
var httpContextArg = Expression . Parameter ( typeof ( HttpContext ) , "httpContext" ) ;
@@ -149,12 +137,15 @@ private static Func<T, HttpContext, IServiceProvider, Task> Compile<T>(MethodInf
149
137
throw new NotSupportedException ( Resources . FormatException_InvokeDoesNotSupportRefOrOutParams ( InvokeMethodName ) ) ;
150
138
}
151
139
152
- var parameterTypeExpression = new Expression [ ] {
153
- providerArg ,
154
- Expression . Constant ( parameterType , typeof ( Type ) ) ,
155
- Expression . Constant ( methodinfo . DeclaringType , typeof ( Type ) )
156
- } ;
157
- methodArguments [ i ] = Expression . Convert ( Expression . Call ( GetServiceInfo , parameterTypeExpression ) , parameterType ) ;
140
+ var parameterTypeExpression = new Expression [ ]
141
+ {
142
+ providerArg ,
143
+ Expression . Constant ( parameterType , typeof ( Type ) ) ,
144
+ Expression . Constant ( methodinfo . DeclaringType , typeof ( Type ) )
145
+ } ;
146
+
147
+ var getServiceCall = Expression . Call ( GetServiceInfo , parameterTypeExpression ) ;
148
+ methodArguments [ i ] = Expression . Convert ( getServiceCall , parameterType ) ;
158
149
}
159
150
160
151
Expression middlewareInstanceArg = instanceArg ;
0 commit comments