|
|
@@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
{
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(@delegate);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(@delegate, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
BindingFlags.NonPublic | BindingFlags.Static,
|
|
|
new[] { typeof(HttpContext) });
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(methodInfo!);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(methodInfo!, new EmptyServiceProvdier());
|
|
|
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
|
|
|
@@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
return new TestNonStaticActionClass(2);
|
|
|
}
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(methodInfo!, _ => GetTarget());
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(methodInfo!, new EmptyServiceProvdier(), _ => GetTarget());
|
|
|
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
|
|
|
@@ -181,10 +181,12 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
BindingFlags.NonPublic | BindingFlags.Static,
|
|
|
new[] { typeof(HttpContext) });
|
|
|
|
|
|
- var exNullAction = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(action: null!));
|
|
|
- var exNullMethodInfo1 = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(methodInfo: null!));
|
|
|
- var exNullMethodInfo2 = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(methodInfo: null!, _ => 0));
|
|
|
- var exNullTargetFactory = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(methodInfo!, targetFactory: null!));
|
|
|
+ var serviceProvider = new EmptyServiceProvdier();
|
|
|
+
|
|
|
+ var exNullAction = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(action: null!, serviceProvider));
|
|
|
+ var exNullMethodInfo1 = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(methodInfo: null!, serviceProvider));
|
|
|
+ var exNullMethodInfo2 = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(methodInfo: null!, serviceProvider, _ => 0));
|
|
|
+ var exNullTargetFactory = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(methodInfo!, serviceProvider, targetFactory: null!));
|
|
|
|
|
|
Assert.Equal("action", exNullAction.ParamName);
|
|
|
Assert.Equal("methodInfo", exNullMethodInfo1.ParamName);
|
|
|
@@ -206,7 +208,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
httpContext.Request.RouteValues[paramName] = originalRouteParam.ToString(NumberFormatInfo.InvariantInfo);
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, int>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, int>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -233,7 +235,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
{
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, int>)TestOptional);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, int>)TestOptional, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -245,7 +247,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
{
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, int>)TestOptional);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, int>)TestOptional, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -257,7 +259,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
{
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, string>)TestOptionalString);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, string>)TestOptionalString, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -274,7 +276,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
|
|
|
httpContext.Request.RouteValues[paramName] = originalRouteParam.ToString(NumberFormatInfo.InvariantInfo);
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, int>)TestOptional);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, int>)TestOptional, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -297,7 +299,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
httpContext.Request.RouteValues[specifiedName] = originalRouteParam.ToString(NumberFormatInfo.InvariantInfo);
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<int>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<int>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -320,7 +322,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
httpContext.Request.RouteValues[unmatchedName] = unmatchedRouteParam.ToString(NumberFormatInfo.InvariantInfo);
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<int>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<int>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -399,7 +401,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
httpContext.Request.RouteValues["tryParsable"] = routeValue;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(action);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(action, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -416,7 +418,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
["tryParsable"] = routeValue
|
|
|
});
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(action);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(action, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -437,8 +439,9 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
|
|
|
var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, int>)((httpContext, tryParsable) =>
|
|
|
{
|
|
|
- httpContext.Items["tryParsable"] = tryParsable;
|
|
|
- }));
|
|
|
+ httpContext.Items["tryParsable"] = tryParsable;
|
|
|
+ }),
|
|
|
+ new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -466,7 +469,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
[MemberData(nameof(DelegatesWithAttributesOnNotTryParsableParameters))]
|
|
|
public void CreateThrowsInvalidOperationExceptionWhenAttributeRequiresTryParseMethodThatDoesNotExist(Delegate action)
|
|
|
{
|
|
|
- var ex = Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create(action));
|
|
|
+ var ex = Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create(action, new EmptyServiceProvdier()));
|
|
|
Assert.Equal("No public static bool Object.TryParse(string, out Object) method found for notTryParsable.", ex.Message);
|
|
|
}
|
|
|
|
|
|
@@ -475,7 +478,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
{
|
|
|
var unnamedParameter = Expression.Parameter(typeof(int));
|
|
|
var lambda = Expression.Lambda(Expression.Block(), unnamedParameter);
|
|
|
- var ex = Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create((Action<int>)lambda.Compile()));
|
|
|
+ var ex = Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create((Action<int>)lambda.Compile(), new EmptyServiceProvdier()));
|
|
|
Assert.Equal("A parameter does not have a name! Was it genererated? All parameters must be named.", ex.Message);
|
|
|
}
|
|
|
|
|
|
@@ -498,7 +501,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
httpContext.Features.Set<IHttpRequestLifetimeFeature>(new TestHttpRequestLifetimeFeature());
|
|
|
httpContext.RequestServices = serviceCollection.BuildServiceProvider();
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<int, int>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<int, int>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -540,7 +543,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
httpContext.Request.Query = query;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<int>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<int>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -563,7 +566,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
httpContext.Request.Headers[customHeaderName] = originalHeaderParam.ToString(NumberFormatInfo.InvariantInfo);
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<int>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<int>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -607,7 +610,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var requestBodyBytes = JsonSerializer.SerializeToUtf8Bytes(originalTodo);
|
|
|
httpContext.Request.Body = new MemoryStream(requestBodyBytes);
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(action);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(action, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -624,7 +627,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
httpContext.Request.Headers["Content-Type"] = "application/json";
|
|
|
httpContext.Request.Headers["Content-Length"] = "0";
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(action);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(action, new EmptyServiceProvdier());
|
|
|
|
|
|
await Assert.ThrowsAsync<JsonException>(() => requestDelegate(httpContext));
|
|
|
}
|
|
|
@@ -643,7 +646,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
httpContext.Request.Headers["Content-Type"] = "application/json";
|
|
|
httpContext.Request.Headers["Content-Length"] = "0";
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<Todo>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<Todo>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -667,7 +670,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
httpContext.Request.Headers["Content-Type"] = "application/json";
|
|
|
httpContext.Request.Headers["Content-Length"] = "0";
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<BodyStruct>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<BodyStruct>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -694,7 +697,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
httpContext.Features.Set<IHttpRequestLifetimeFeature>(new TestHttpRequestLifetimeFeature());
|
|
|
httpContext.RequestServices = serviceCollection.BuildServiceProvider();
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<Todo>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<Todo>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -727,7 +730,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
httpContext.Features.Set<IHttpRequestLifetimeFeature>(new TestHttpRequestLifetimeFeature());
|
|
|
httpContext.RequestServices = serviceCollection.BuildServiceProvider();
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<Todo>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<Todo>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -748,9 +751,9 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
void TestInferredInvalidAction(Todo value1, Todo value2) { }
|
|
|
void TestBothInvalidAction(Todo value1, [FromBody] int value2) { }
|
|
|
|
|
|
- Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create((Action<int, int>)TestAttributedInvalidAction));
|
|
|
- Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create((Action<Todo, Todo>)TestInferredInvalidAction));
|
|
|
- Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create((Action<Todo, int>)TestBothInvalidAction));
|
|
|
+ Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create((Action<int, int>)TestAttributedInvalidAction, new EmptyServiceProvdier()));
|
|
|
+ Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create((Action<Todo, Todo>)TestInferredInvalidAction, new EmptyServiceProvdier()));
|
|
|
+ Assert.Throws<InvalidOperationException>(() => RequestDelegateFactory.Create((Action<Todo, int>)TestBothInvalidAction, new EmptyServiceProvdier()));
|
|
|
}
|
|
|
|
|
|
public static object[][] FromServiceActions
|
|
|
@@ -777,12 +780,18 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
httpContext.Items.Add("service", myServices.Single());
|
|
|
}
|
|
|
|
|
|
+ void TestImpliedFromServiceBasedOnContainer(HttpContext httpContext, MyService myService)
|
|
|
+ {
|
|
|
+ httpContext.Items.Add("service", myService);
|
|
|
+ }
|
|
|
+
|
|
|
return new object[][]
|
|
|
{
|
|
|
new[] { (Action<HttpContext, MyService>)TestExplicitFromService },
|
|
|
new[] { (Action<HttpContext, IEnumerable<MyService>>)TestExplicitFromIEnumerableService },
|
|
|
new[] { (Action<HttpContext, IMyService>)TestImpliedFromService },
|
|
|
new[] { (Action<HttpContext, IEnumerable<MyService>>)TestImpliedIEnumerableFromService },
|
|
|
+ new[] { (Action<HttpContext, MyService>)TestImpliedFromServiceBasedOnContainer },
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
@@ -797,10 +806,14 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
serviceCollection.AddSingleton(myOriginalService);
|
|
|
serviceCollection.AddSingleton<IMyService>(myOriginalService);
|
|
|
|
|
|
+ var services = serviceCollection.BuildServiceProvider();
|
|
|
+
|
|
|
+ using var requestScoped = services.CreateScope();
|
|
|
+
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
- httpContext.RequestServices = serviceCollection.BuildServiceProvider();
|
|
|
+ httpContext.RequestServices = requestScoped.ServiceProvider;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(action);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(action, services);
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -812,9 +825,9 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
public async Task RequestDelegateRequiresServiceForAllFromServiceParameters(Delegate action)
|
|
|
{
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
- httpContext.RequestServices = new ServiceCollection().BuildServiceProvider();
|
|
|
+ httpContext.RequestServices = new EmptyServiceProvdier();
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(action);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(action, new EmptyServiceProvdier());
|
|
|
|
|
|
await Assert.ThrowsAsync<InvalidOperationException>(() => requestDelegate(httpContext));
|
|
|
}
|
|
|
@@ -831,7 +844,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -854,7 +867,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
RequestAborted = cts.Token
|
|
|
};
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create((Action<CancellationToken>)TestAction);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create((Action<CancellationToken>)TestAction, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -898,7 +911,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var responseBodyStream = new MemoryStream();
|
|
|
httpContext.Response.Body = responseBodyStream;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(@delegate);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(@delegate, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -947,7 +960,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var responseBodyStream = new MemoryStream();
|
|
|
httpContext.Response.Body = responseBodyStream;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(@delegate);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(@delegate, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -990,7 +1003,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var responseBodyStream = new MemoryStream();
|
|
|
httpContext.Response.Body = responseBodyStream;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(@delegate);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(@delegate, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -1031,7 +1044,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var responseBodyStream = new MemoryStream();
|
|
|
httpContext.Response.Body = responseBodyStream;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(@delegate);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(@delegate, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -1072,7 +1085,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var responseBodyStream = new MemoryStream();
|
|
|
httpContext.Response.Body = responseBodyStream;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(@delegate);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(@delegate, new EmptyServiceProvdier());
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -1110,7 +1123,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var responseBodyStream = new MemoryStream();
|
|
|
httpContext.Response.Body = responseBodyStream;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(@delegate);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(@delegate, serviceProvider: null);
|
|
|
|
|
|
var exception = await Assert.ThrowsAnyAsync<InvalidOperationException>(async () => await requestDelegate(httpContext));
|
|
|
Assert.Contains(message, exception.Message);
|
|
|
@@ -1155,7 +1168,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
var responseBodyStream = new MemoryStream();
|
|
|
httpContext.Response.Body = responseBodyStream;
|
|
|
|
|
|
- var requestDelegate = RequestDelegateFactory.Create(@delegate);
|
|
|
+ var requestDelegate = RequestDelegateFactory.Create(@delegate, serviceProvider: null);
|
|
|
|
|
|
await requestDelegate(httpContext);
|
|
|
|
|
|
@@ -1268,6 +1281,30 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private class EmptyServiceProvdier : IServiceScope, IServiceProvider, IServiceScopeFactory
|
|
|
+ {
|
|
|
+ public IServiceProvider ServiceProvider => this;
|
|
|
+
|
|
|
+ public IServiceScope CreateScope()
|
|
|
+ {
|
|
|
+ return new EmptyServiceProvdier();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Dispose()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public object? GetService(Type serviceType)
|
|
|
+ {
|
|
|
+ if (serviceType == typeof(IServiceScopeFactory))
|
|
|
+ {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private class TestHttpRequestLifetimeFeature : IHttpRequestLifetimeFeature
|
|
|
{
|
|
|
private readonly CancellationTokenSource _requestAbortedCts = new CancellationTokenSource();
|