From 59d636f6bde6104121a19e4e0229a76bb46b8ab1 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Mon, 8 Jul 2019 20:59:56 -0700 Subject: [PATCH] Make some MVC routing types public again (#11969) * Make some types public again We've heard some demand to make these types public again after trying them as internal. API Versioning calls the action selector and handles AmbiguousActionException to give more specific responses. API Versioning (and others) look for HttpMethodActionConstraint to determine the supported HTTP methods of an IRouter-based action method. * fix the build --- ...osoft.AspNetCore.Mvc.Core.netcoreapp3.0.cs | 13 ++++++++++ .../HttpMethodActionConstraint.cs | 25 +++++++++++++++++-- .../AmbiguousActionException.cs | 11 +++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/Mvc/Mvc.Core/ref/Microsoft.AspNetCore.Mvc.Core.netcoreapp3.0.cs b/src/Mvc/Mvc.Core/ref/Microsoft.AspNetCore.Mvc.Core.netcoreapp3.0.cs index a895709b24..ce0bbc1f92 100644 --- a/src/Mvc/Mvc.Core/ref/Microsoft.AspNetCore.Mvc.Core.netcoreapp3.0.cs +++ b/src/Mvc/Mvc.Core/ref/Microsoft.AspNetCore.Mvc.Core.netcoreapp3.0.cs @@ -1270,6 +1270,14 @@ namespace Microsoft.AspNetCore.Mvc.ActionConstraints public bool Accept(Microsoft.AspNetCore.Mvc.ActionConstraints.ActionConstraintContext context) { throw null; } public abstract bool IsValidForRequest(Microsoft.AspNetCore.Routing.RouteContext routeContext, Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor action); } + public partial class HttpMethodActionConstraint : Microsoft.AspNetCore.Mvc.ActionConstraints.IActionConstraint, Microsoft.AspNetCore.Mvc.ActionConstraints.IActionConstraintMetadata + { + public static readonly int HttpMethodConstraintOrder; + public HttpMethodActionConstraint(System.Collections.Generic.IEnumerable httpMethods) { } + public System.Collections.Generic.IEnumerable HttpMethods { get { throw null; } } + public int Order { get { throw null; } } + public virtual bool Accept(Microsoft.AspNetCore.Mvc.ActionConstraints.ActionConstraintContext context) { throw null; } + } } namespace Microsoft.AspNetCore.Mvc.ApiExplorer { @@ -1941,6 +1949,11 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure { public ActionResultStatusCodeAttribute() { } } + public partial class AmbiguousActionException : System.InvalidOperationException + { + protected AmbiguousActionException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } + public AmbiguousActionException(string message) { } + } public partial class CompatibilitySwitch : Microsoft.AspNetCore.Mvc.Infrastructure.ICompatibilitySwitch where TValue : struct { public CompatibilitySwitch(string name) { } diff --git a/src/Mvc/Mvc.Core/src/ActionConstraints/HttpMethodActionConstraint.cs b/src/Mvc/Mvc.Core/src/ActionConstraints/HttpMethodActionConstraint.cs index 4385e734e5..a8a462da7e 100644 --- a/src/Mvc/Mvc.Core/src/ActionConstraints/HttpMethodActionConstraint.cs +++ b/src/Mvc/Mvc.Core/src/ActionConstraints/HttpMethodActionConstraint.cs @@ -4,16 +4,32 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using Microsoft.AspNetCore.Routing; namespace Microsoft.AspNetCore.Mvc.ActionConstraints { - internal class HttpMethodActionConstraint : IActionConstraint + /// + /// The implementation of used to enforce + /// HTTP method filtering when MVC is used with legacy + /// support. The can be used to determine + /// the set of HTTP methods supported by an action. + /// + public class HttpMethodActionConstraint : IActionConstraint { + /// + /// The value used by . + /// public static readonly int HttpMethodConstraintOrder = 100; private readonly IReadOnlyList _httpMethods; - // Empty collection means any method will be accepted. + /// + /// Creates a new instance of . + /// + /// + /// The list of HTTP methods to allow. Providing an empty list will allow + /// any HTTP method. + /// public HttpMethodActionConstraint(IEnumerable httpMethods) { if (httpMethods == null) @@ -36,10 +52,15 @@ namespace Microsoft.AspNetCore.Mvc.ActionConstraints _httpMethods = new ReadOnlyCollection(methods); } + /// + /// Gets the list of allowed HTTP methods. Will return an empty list if all HTTP methods are allowed. + /// public IEnumerable HttpMethods => _httpMethods; + /// public int Order => HttpMethodConstraintOrder; + /// public virtual bool Accept(ActionConstraintContext context) { if (context == null) diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/AmbiguousActionException.cs b/src/Mvc/Mvc.Core/src/Infrastructure/AmbiguousActionException.cs index afe28c0209..145b5713e0 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/AmbiguousActionException.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/AmbiguousActionException.cs @@ -10,13 +10,22 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure /// An exception which indicates multiple matches in action selection. /// [Serializable] - internal class AmbiguousActionException : InvalidOperationException + public class AmbiguousActionException : InvalidOperationException { + /// + /// Creates a new instance of . + /// + /// The exception message. public AmbiguousActionException(string message) : base(message) { } + /// + /// Framework infrastructure. Do not call directly. + /// + /// + /// protected AmbiguousActionException(SerializationInfo info, StreamingContext context) : base(info, context) {