No HttpContext to route constraints in MvcEndpointDataSource (#8436)

This commit is contained in:
James Newton-King 2018-09-11 10:12:09 +12:00 committed by GitHub
parent f573b8840a
commit 6e27a04bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 22 deletions

View File

@ -110,8 +110,7 @@ namespace Microsoft.AspNetCore.Mvc.Performance
{ {
var dataSource = new MvcEndpointDataSource( var dataSource = new MvcEndpointDataSource(
actionDescriptorCollectionProvider, actionDescriptorCollectionProvider,
new MvcEndpointInvokerFactory(new ActionInvokerFactory(Array.Empty<IActionInvokerProvider>())), new MvcEndpointInvokerFactory(new ActionInvokerFactory(Array.Empty<IActionInvokerProvider>())));
new MockServiceProvider());
return dataSource; return dataSource;
} }
@ -126,14 +125,6 @@ namespace Microsoft.AspNetCore.Mvc.Performance
public ActionDescriptorCollection ActionDescriptors { get; } public ActionDescriptorCollection ActionDescriptors { get; }
} }
private class MockServiceProvider : IServiceProvider
{
public object GetService(Type serviceType)
{
throw new NotImplementedException();
}
}
private class MockParameterPolicyFactory : ParameterPolicyFactory private class MockParameterPolicyFactory : ParameterPolicyFactory
{ {
public override IParameterPolicy Create(RoutePatternParameterPart parameter, string inlineText) public override IParameterPolicy Create(RoutePatternParameterPart parameter, string inlineText)

View File

@ -23,7 +23,6 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{ {
private readonly IActionDescriptorCollectionProvider _actions; private readonly IActionDescriptorCollectionProvider _actions;
private readonly MvcEndpointInvokerFactory _invokerFactory; private readonly MvcEndpointInvokerFactory _invokerFactory;
private readonly DefaultHttpContext _httpContextInstance;
// The following are protected by this lock for WRITES only. This pattern is similar // The following are protected by this lock for WRITES only. This pattern is similar
// to DefaultActionDescriptorChangeProvider - see comments there for details on // to DefaultActionDescriptorChangeProvider - see comments there for details on
@ -35,8 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
public MvcEndpointDataSource( public MvcEndpointDataSource(
IActionDescriptorCollectionProvider actions, IActionDescriptorCollectionProvider actions,
MvcEndpointInvokerFactory invokerFactory, MvcEndpointInvokerFactory invokerFactory)
IServiceProvider serviceProvider)
{ {
if (actions == null) if (actions == null)
{ {
@ -48,14 +46,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
throw new ArgumentNullException(nameof(invokerFactory)); throw new ArgumentNullException(nameof(invokerFactory));
} }
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
_actions = actions; _actions = actions;
_invokerFactory = invokerFactory; _invokerFactory = invokerFactory;
_httpContextInstance = new DefaultHttpContext() { RequestServices = serviceProvider };
ConventionalEndpointInfos = new List<MvcEndpointInfo>(); ConventionalEndpointInfos = new List<MvcEndpointInfo>();
@ -358,7 +350,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{ {
foreach (var constraint in constraints) foreach (var constraint in constraints)
{ {
if (!constraint.Match(_httpContextInstance, NullRouter.Instance, routeKey, new RouteValueDictionary(action.RouteValues), RouteDirection.IncomingRequest)) if (!constraint.Match(httpContext: null, NullRouter.Instance, routeKey, new RouteValueDictionary(action.RouteValues), RouteDirection.IncomingRequest))
{ {
// Did not match constraint // Did not match constraint
return false; return false;

View File

@ -711,8 +711,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var dataSource = new MvcEndpointDataSource( var dataSource = new MvcEndpointDataSource(
actionDescriptorCollectionProvider, actionDescriptorCollectionProvider,
mvcEndpointInvokerFactory ?? new MvcEndpointInvokerFactory(new ActionInvokerFactory(Array.Empty<IActionInvokerProvider>())), mvcEndpointInvokerFactory ?? new MvcEndpointInvokerFactory(new ActionInvokerFactory(Array.Empty<IActionInvokerProvider>())));
services.BuildServiceProvider());
return dataSource; return dataSource;
} }