From 57d64206bfa7bd833b602c6566cedd59289cf263 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 20 Aug 2021 13:42:18 -0700 Subject: [PATCH 1/6] Minimal APIs naming cleanup --- ...s => DelegateEndpointConventionBuilder.cs} | 6 +- ...DelegateEndpointRouteBuilderExtensions.cs} | 98 +++++++++---------- src/Http/Routing/src/PublicAPI.Unshipped.txt | 24 ++--- ...inimalActionTest.cs => MapDelegateTest.cs} | 2 +- ...gateEndpointRouteBuilderExtensionsTest.cs} | 2 +- 5 files changed, 66 insertions(+), 66 deletions(-) rename src/Http/Routing/src/Builder/{MinimalActionEndpointConventionBuilder.cs => DelegateEndpointConventionBuilder.cs} (79%) rename src/Http/Routing/src/Builder/{MinimalActionEndpointRouteBuilderExtensions.cs => DelegateEndpointRouteBuilderExtensions.cs} (78%) rename src/Http/Routing/test/FunctionalTests/{MinimalActionTest.cs => MapDelegateTest.cs} (98%) rename src/Http/Routing/test/UnitTests/Builder/{MinimalActionEndpointRouteBuilderExtensionsTest.cs => DelegateEndpointRouteBuilderExtensionsTest.cs} (99%) diff --git a/src/Http/Routing/src/Builder/MinimalActionEndpointConventionBuilder.cs b/src/Http/Routing/src/Builder/DelegateEndpointConventionBuilder.cs similarity index 79% rename from src/Http/Routing/src/Builder/MinimalActionEndpointConventionBuilder.cs rename to src/Http/Routing/src/Builder/DelegateEndpointConventionBuilder.cs index cdcf7f6870a2..d5884ad8d915 100644 --- a/src/Http/Routing/src/Builder/MinimalActionEndpointConventionBuilder.cs +++ b/src/Http/Routing/src/Builder/DelegateEndpointConventionBuilder.cs @@ -9,16 +9,16 @@ namespace Microsoft.AspNetCore.Builder /// /// Builds conventions that will be used for customization of MapAction instances. /// - public sealed class MinimalActionEndpointConventionBuilder : IEndpointConventionBuilder + public sealed class DelegateEndpointConventionBuilder : IEndpointConventionBuilder { private readonly List _endpointConventionBuilders; - internal MinimalActionEndpointConventionBuilder(IEndpointConventionBuilder endpointConventionBuilder) + internal DelegateEndpointConventionBuilder(IEndpointConventionBuilder endpointConventionBuilder) { _endpointConventionBuilders = new List() { endpointConventionBuilder }; } - internal MinimalActionEndpointConventionBuilder(List endpointConventionBuilders) + internal DelegateEndpointConventionBuilder(List endpointConventionBuilders) { _endpointConventionBuilders = endpointConventionBuilders; } diff --git a/src/Http/Routing/src/Builder/MinimalActionEndpointRouteBuilderExtensions.cs b/src/Http/Routing/src/Builder/DelegateEndpointRouteBuilderExtensions.cs similarity index 78% rename from src/Http/Routing/src/Builder/MinimalActionEndpointRouteBuilderExtensions.cs rename to src/Http/Routing/src/Builder/DelegateEndpointRouteBuilderExtensions.cs index d209bd774a57..7158dc05f8a3 100644 --- a/src/Http/Routing/src/Builder/MinimalActionEndpointRouteBuilderExtensions.cs +++ b/src/Http/Routing/src/Builder/DelegateEndpointRouteBuilderExtensions.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Builder /// /// Provides extension methods for to define HTTP API endpoints. /// - public static class MinimalActionEndpointRouteBuilderExtensions + public static class DelegateEndpointRouteBuilderExtensions { // Avoid creating a new array every call private static readonly string[] GetVerb = new[] { "GET" }; @@ -31,14 +31,14 @@ public static class MinimalActionEndpointRouteBuilderExtensions /// /// The to add the route to. /// The route pattern. - /// The delegate executed when the endpoint is matched. + /// The delegate executed when the endpoint is matched. /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder MapGet( + public static DelegateEndpointConventionBuilder MapGet( this IEndpointRouteBuilder endpoints, string pattern, - Delegate action) + Delegate handler) { - return MapMethods(endpoints, pattern, GetVerb, action); + return MapMethods(endpoints, pattern, GetVerb, handler); } /// @@ -47,14 +47,14 @@ public static MinimalActionEndpointConventionBuilder MapGet( /// /// The to add the route to. /// The route pattern. - /// The delegate executed when the endpoint is matched. + /// The delegate executed when the endpoint is matched. /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder MapPost( + public static DelegateEndpointConventionBuilder MapPost( this IEndpointRouteBuilder endpoints, string pattern, - Delegate action) + Delegate handler) { - return MapMethods(endpoints, pattern, PostVerb, action); + return MapMethods(endpoints, pattern, PostVerb, handler); } /// @@ -63,14 +63,14 @@ public static MinimalActionEndpointConventionBuilder MapPost( /// /// The to add the route to. /// The route pattern. - /// The delegate executed when the endpoint is matched. + /// The delegate executed when the endpoint is matched. /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder MapPut( + public static DelegateEndpointConventionBuilder MapPut( this IEndpointRouteBuilder endpoints, string pattern, - Delegate action) + Delegate handler) { - return MapMethods(endpoints, pattern, PutVerb, action); + return MapMethods(endpoints, pattern, PutVerb, handler); } /// @@ -79,14 +79,14 @@ public static MinimalActionEndpointConventionBuilder MapPut( /// /// The to add the route to. /// The route pattern. - /// The delegate executed when the endpoint is matched. + /// The delegate executed when the endpoint is matched. /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder MapDelete( + public static DelegateEndpointConventionBuilder MapDelete( this IEndpointRouteBuilder endpoints, string pattern, - Delegate action) + Delegate handler) { - return MapMethods(endpoints, pattern, DeleteVerb, action); + return MapMethods(endpoints, pattern, DeleteVerb, handler); } /// @@ -95,21 +95,21 @@ public static MinimalActionEndpointConventionBuilder MapDelete( /// /// The to add the route to. /// The route pattern. - /// The delegate executed when the endpoint is matched. + /// The delegate executed when the endpoint is matched. /// HTTP methods that the endpoint will match. /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder MapMethods( + public static DelegateEndpointConventionBuilder MapMethods( this IEndpointRouteBuilder endpoints, string pattern, IEnumerable httpMethods, - Delegate action) + Delegate handler) { if (httpMethods is null) { throw new ArgumentNullException(nameof(httpMethods)); } - var builder = endpoints.Map(RoutePatternFactory.Parse(pattern), action); + var builder = endpoints.Map(RoutePatternFactory.Parse(pattern), handler); // Prepends the HTTP method to the DisplayName produced with pattern + method name builder.Add(b => b.DisplayName = $"HTTP: {string.Join(", ", httpMethods)} {b.DisplayName}"); builder.WithMetadata(new HttpMethodMetadata(httpMethods)); @@ -122,14 +122,14 @@ public static MinimalActionEndpointConventionBuilder MapMethods( /// /// The to add the route to. /// The route pattern. - /// The delegate executed when the endpoint is matched. + /// The delegate executed when the endpoint is matched. /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder Map( + public static DelegateEndpointConventionBuilder Map( this IEndpointRouteBuilder endpoints, string pattern, - Delegate action) + Delegate handler) { - return Map(endpoints, RoutePatternFactory.Parse(pattern), action); + return Map(endpoints, RoutePatternFactory.Parse(pattern), handler); } /// @@ -138,12 +138,12 @@ public static MinimalActionEndpointConventionBuilder Map( /// /// The to add the route to. /// The route pattern. - /// The delegate executed when the endpoint is matched. + /// The delegate executed when the endpoint is matched. /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder Map( + public static DelegateEndpointConventionBuilder Map( this IEndpointRouteBuilder endpoints, RoutePattern pattern, - Delegate action) + Delegate handler) { if (endpoints is null) { @@ -155,9 +155,9 @@ public static MinimalActionEndpointConventionBuilder Map( throw new ArgumentNullException(nameof(pattern)); } - if (action is null) + if (handler is null) { - throw new ArgumentNullException(nameof(action)); + throw new ArgumentNullException(nameof(handler)); } const int defaultOrder = 0; @@ -174,7 +174,7 @@ public static MinimalActionEndpointConventionBuilder Map( RouteParameterNames = routeParams }; - var requestDelegateResult = RequestDelegateFactory.Create(action, options); + var requestDelegateResult = RequestDelegateFactory.Create(handler, options); var builder = new RouteEndpointBuilder( requestDelegateResult.RequestDelegate, @@ -185,18 +185,18 @@ public static MinimalActionEndpointConventionBuilder Map( }; // REVIEW: Should we add an IActionMethodMetadata with just MethodInfo on it so we are - // explicit about the MethodInfo representing the "action" and not the RequestDelegate? + // explicit about the MethodInfo representing the "handler" and not the RequestDelegate? // Add MethodInfo as metadata to assist with OpenAPI generation for the endpoint. - builder.Metadata.Add(action.Method); + builder.Metadata.Add(handler.Method); // Methods defined in a top-level program are generated as statics so the delegate // target will be null. Inline lambdas are compiler generated method so they can // be filtered that way. - if (GeneratedNameParser.TryParseLocalFunctionName(action.Method.Name, out var endpointName) - || !TypeHelper.IsCompilerGeneratedMethod(action.Method)) + if (GeneratedNameParser.TryParseLocalFunctionName(handler.Method.Name, out var endpointName) + || !TypeHelper.IsCompilerGeneratedMethod(handler.Method)) { - endpointName ??= action.Method.Name; + endpointName ??= handler.Method.Name; builder.Metadata.Add(new EndpointNameMetadata(endpointName)); builder.Metadata.Add(new RouteNameMetadata(endpointName)); @@ -204,7 +204,7 @@ public static MinimalActionEndpointConventionBuilder Map( } // Add delegate attributes as metadata - var attributes = action.Method.GetCustomAttributes(); + var attributes = handler.Method.GetCustomAttributes(); // Add add request delegate metadata foreach (var metadata in requestDelegateResult.EndpointMetadata) @@ -228,7 +228,7 @@ public static MinimalActionEndpointConventionBuilder Map( endpoints.DataSources.Add(dataSource); } - return new MinimalActionEndpointConventionBuilder(dataSource.AddEndpointBuilder(builder)); + return new DelegateEndpointConventionBuilder(dataSource.AddEndpointBuilder(builder)); } /// @@ -236,7 +236,7 @@ public static MinimalActionEndpointConventionBuilder Map( /// requests for non-file-names with the lowest possible priority. /// /// The to add the route to. - /// The delegate executed when the endpoint is matched. + /// The delegate executed when the endpoint is matched. /// A that can be used to further customize the endpoint. /// /// @@ -250,19 +250,19 @@ public static MinimalActionEndpointConventionBuilder Map( /// {*path:nonfile}. The order of the registered endpoint will be int.MaxValue. /// /// - public static MinimalActionEndpointConventionBuilder MapFallback(this IEndpointRouteBuilder endpoints, Delegate action) + public static DelegateEndpointConventionBuilder MapFallback(this IEndpointRouteBuilder endpoints, Delegate handler) { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } - if (action == null) + if (handler == null) { - throw new ArgumentNullException(nameof(action)); + throw new ArgumentNullException(nameof(handler)); } - return endpoints.MapFallback("{*path:nonfile}", action); + return endpoints.MapFallback("{*path:nonfile}", handler); } /// @@ -271,7 +271,7 @@ public static MinimalActionEndpointConventionBuilder MapFallback(this IEndpointR /// /// The to add the route to. /// The route pattern. - /// The delegate executed when the endpoint is matched. + /// The delegate executed when the endpoint is matched. /// A that can be used to further customize the endpoint. /// /// @@ -286,10 +286,10 @@ public static MinimalActionEndpointConventionBuilder MapFallback(this IEndpointR /// to exclude requests for static files. /// /// - public static MinimalActionEndpointConventionBuilder MapFallback( + public static DelegateEndpointConventionBuilder MapFallback( this IEndpointRouteBuilder endpoints, string pattern, - Delegate action) + Delegate handler) { if (endpoints == null) { @@ -301,12 +301,12 @@ public static MinimalActionEndpointConventionBuilder MapFallback( throw new ArgumentNullException(nameof(pattern)); } - if (action == null) + if (handler == null) { - throw new ArgumentNullException(nameof(action)); + throw new ArgumentNullException(nameof(handler)); } - var conventionBuilder = endpoints.Map(pattern, action); + var conventionBuilder = endpoints.Map(pattern, handler); conventionBuilder.WithDisplayName("Fallback " + pattern); conventionBuilder.Add(b => ((RouteEndpointBuilder)b).Order = int.MaxValue); return conventionBuilder; diff --git a/src/Http/Routing/src/PublicAPI.Unshipped.txt b/src/Http/Routing/src/PublicAPI.Unshipped.txt index 723c45f65664..e05751d090a0 100644 --- a/src/Http/Routing/src/PublicAPI.Unshipped.txt +++ b/src/Http/Routing/src/PublicAPI.Unshipped.txt @@ -5,9 +5,9 @@ *REMOVED*Microsoft.AspNetCore.Routing.IRouteNameMetadata.RouteName.get -> string! *REMOVED*Microsoft.AspNetCore.Routing.RouteNameMetadata.RouteName.get -> string! *REMOVED*Microsoft.AspNetCore.Routing.RouteNameMetadata.RouteNameMetadata(string! routeName) -> void -Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder -Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder.Add(System.Action! convention) -> void -Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions +Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder +Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder.Add(System.Action! convention) -> void +Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions Microsoft.AspNetCore.Routing.DataTokensMetadata.DataTokens.get -> System.Collections.Generic.IReadOnlyDictionary! Microsoft.AspNetCore.Routing.DataTokensMetadata.DataTokensMetadata(System.Collections.Generic.IReadOnlyDictionary! dataTokens) -> void Microsoft.AspNetCore.Routing.IDataTokensMetadata.DataTokens.get -> System.Collections.Generic.IReadOnlyDictionary! @@ -16,15 +16,6 @@ Microsoft.AspNetCore.Routing.Matching.IParameterLiteralNodeMatchingPolicy Microsoft.AspNetCore.Routing.Matching.IParameterLiteralNodeMatchingPolicy.MatchesLiteral(string! parameterName, string! literal) -> bool Microsoft.AspNetCore.Routing.RouteNameMetadata.RouteName.get -> string? Microsoft.AspNetCore.Routing.RouteNameMetadata.RouteNameMetadata(string? routeName) -> void -static Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.Map(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, Microsoft.AspNetCore.Routing.Patterns.RoutePattern! pattern, System.Delegate! action) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.Map(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! action) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.MapDelete(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! action) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.MapFallback(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, System.Delegate! action) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.MapFallback(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! action) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.MapGet(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! action) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.MapMethods(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Collections.Generic.IEnumerable! httpMethods, System.Delegate! action) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.MapPost(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! action) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.MapPut(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! action) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! Microsoft.AspNetCore.Routing.IEndpointGroupNameMetadata Microsoft.AspNetCore.Routing.IEndpointGroupNameMetadata.EndpointGroupName.get -> string! Microsoft.AspNetCore.Routing.EndpointGroupNameAttribute @@ -33,6 +24,15 @@ Microsoft.AspNetCore.Routing.EndpointGroupNameAttribute.EndpointGroupName.get -> Microsoft.AspNetCore.Routing.EndpointNameAttribute Microsoft.AspNetCore.Routing.EndpointNameAttribute.EndpointNameAttribute(string! endpointName) -> void Microsoft.AspNetCore.Routing.EndpointNameAttribute.EndpointName.get -> string! +static Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions.Map(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, Microsoft.AspNetCore.Routing.Patterns.RoutePattern! pattern, System.Delegate! handler) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions.Map(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! handler) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions.MapDelete(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! handler) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions.MapFallback(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, System.Delegate! handler) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions.MapFallback(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! handler) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions.MapGet(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! handler) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions.MapMethods(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Collections.Generic.IEnumerable! httpMethods, System.Delegate! handler) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions.MapPost(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! handler) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions.MapPut(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! handler) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! static Microsoft.AspNetCore.Builder.RoutingEndpointConventionBuilderExtensions.WithName(this TBuilder builder, string! endpointName) -> TBuilder static Microsoft.AspNetCore.Builder.RoutingEndpointConventionBuilderExtensions.WithGroupName(this TBuilder builder, string! endpointGroupName) -> TBuilder Microsoft.AspNetCore.Routing.IExcludeFromDescriptionMetadata diff --git a/src/Http/Routing/test/FunctionalTests/MinimalActionTest.cs b/src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs similarity index 98% rename from src/Http/Routing/test/FunctionalTests/MinimalActionTest.cs rename to src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs index 9ab38e541bc6..c992d0aa668c 100644 --- a/src/Http/Routing/test/FunctionalTests/MinimalActionTest.cs +++ b/src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Routing.FunctionalTests { - public class MinimalActionTest + public class MapDelegateTest { [Fact] public async Task MapPost_FromBodyWorksWithJsonPayload() diff --git a/src/Http/Routing/test/UnitTests/Builder/MinimalActionEndpointRouteBuilderExtensionsTest.cs b/src/Http/Routing/test/UnitTests/Builder/DelegateEndpointRouteBuilderExtensionsTest.cs similarity index 99% rename from src/Http/Routing/test/UnitTests/Builder/MinimalActionEndpointRouteBuilderExtensionsTest.cs rename to src/Http/Routing/test/UnitTests/Builder/DelegateEndpointRouteBuilderExtensionsTest.cs index 2d1edcbd7094..2e8989b39396 100644 --- a/src/Http/Routing/test/UnitTests/Builder/MinimalActionEndpointRouteBuilderExtensionsTest.cs +++ b/src/Http/Routing/test/UnitTests/Builder/DelegateEndpointRouteBuilderExtensionsTest.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Builder { - public class MinimalActionEndpointDataSourceBuilderExtensionsTest + public class DelegateEndpointRouteBuilderExtensionsTest { private ModelEndpointDataSource GetBuilderEndpointDataSource(IEndpointRouteBuilder endpointRouteBuilder) { From e225b91cad3bf1496c92473cb34daba889edfcc0 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 20 Aug 2021 13:50:15 -0700 Subject: [PATCH 2/6] Simplify test --- src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs | 6 +++--- .../Microsoft.AspNetCore.Routing.FunctionalTests.csproj | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs b/src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs index c992d0aa668c..690cb236e346 100644 --- a/src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs +++ b/src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs @@ -22,8 +22,6 @@ public class MapDelegateTest [Fact] public async Task MapPost_FromBodyWorksWithJsonPayload() { - Todo EchoTodo([FromRoute] int id, [FromBody] Todo todo) => todo with { Id = id }; - using var host = new HostBuilder() .ConfigureWebHost(webHostBuilder => { @@ -31,7 +29,9 @@ public async Task MapPost_FromBodyWorksWithJsonPayload() .Configure(app => { app.UseRouting(); - app.UseEndpoints(b => b.MapPost("/EchoTodo/{id}", (Func)EchoTodo)); + app.UseEndpoints(b => + b.MapPost("/EchoTodo/{id}", + (int id, Todo todo) => todo with { Id = id })); }) .UseTestServer(); }) diff --git a/src/Http/Routing/test/FunctionalTests/Microsoft.AspNetCore.Routing.FunctionalTests.csproj b/src/Http/Routing/test/FunctionalTests/Microsoft.AspNetCore.Routing.FunctionalTests.csproj index 0913e1a18394..64526f56136a 100644 --- a/src/Http/Routing/test/FunctionalTests/Microsoft.AspNetCore.Routing.FunctionalTests.csproj +++ b/src/Http/Routing/test/FunctionalTests/Microsoft.AspNetCore.Routing.FunctionalTests.csproj @@ -1,4 +1,4 @@ - + $(DefaultNetCoreTargetFramework) @@ -12,7 +12,6 @@ - From 3fb221b13cb7c19da49230b2814a0123649e3734 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 20 Aug 2021 17:36:53 -0700 Subject: [PATCH 3/6] React in OpenApiEndpointConventionBuilderExtensions --- ...nApiEndpointConventionBuilderExtensions.cs | 46 +++++++++---------- src/Mvc/Mvc.Core/src/PublicAPI.Unshipped.txt | 14 +++--- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/Mvc/Mvc.Core/src/Builder/OpenApiEndpointConventionBuilderExtensions.cs b/src/Mvc/Mvc.Core/src/Builder/OpenApiEndpointConventionBuilderExtensions.cs index dbb4326f4465..83ef74a82a7c 100644 --- a/src/Mvc/Mvc.Core/src/Builder/OpenApiEndpointConventionBuilderExtensions.cs +++ b/src/Mvc/Mvc.Core/src/Builder/OpenApiEndpointConventionBuilderExtensions.cs @@ -1,12 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Net.Http.Headers; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http.Metadata; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Routing; namespace Microsoft.AspNetCore.Http @@ -22,9 +18,9 @@ public static class OpenApiEndpointConventionBuilderExtensions /// Adds the to for all builders /// produced by . /// - /// The . - /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder ExcludeFromDescription(this MinimalActionEndpointConventionBuilder builder) + /// The . + /// A that can be used to further customize the endpoint. + public static DelegateEndpointConventionBuilder ExcludeFromDescription(this DelegateEndpointConventionBuilder builder) { builder.WithMetadata(_excludeFromDescriptionMetadataAttribute); @@ -36,13 +32,13 @@ public static MinimalActionEndpointConventionBuilder ExcludeFromDescription(this /// produced by . /// /// The type of the response. - /// The . + /// The . /// The response status code. Defaults to StatusCodes.Status200OK. /// The response content type. Defaults to "application/json". /// Additional response content types the endpoint produces for the supplied status code. - /// A that can be used to further customize the endpoint. + /// A that can be used to further customize the endpoint. #pragma warning disable RS0026 - public static MinimalActionEndpointConventionBuilder Produces(this MinimalActionEndpointConventionBuilder builder, + public static DelegateEndpointConventionBuilder Produces(this DelegateEndpointConventionBuilder builder, #pragma warning restore RS0026 int statusCode = StatusCodes.Status200OK, string? contentType = null, @@ -55,14 +51,14 @@ public static MinimalActionEndpointConventionBuilder Produces(this Mi /// Adds the to for all builders /// produced by . /// - /// The . + /// The . /// The response status code. /// The type of the response. Defaults to null. /// The response content type. Defaults to "application/json" if responseType is not null, otherwise defaults to null. /// Additional response content types the endpoint produces for the supplied status code. - /// A that can be used to further customize the endpoint. + /// A that can be used to further customize the endpoint. #pragma warning disable RS0026 - public static MinimalActionEndpointConventionBuilder Produces(this MinimalActionEndpointConventionBuilder builder, + public static DelegateEndpointConventionBuilder Produces(this DelegateEndpointConventionBuilder builder, #pragma warning restore RS0026 int statusCode, Type? responseType = null, @@ -89,11 +85,11 @@ public static MinimalActionEndpointConventionBuilder Produces(this MinimalAction /// Adds the with a type /// to for all builders produced by . /// - /// The . + /// The . /// The response status code. /// The response content type. Defaults to "application/problem+json". - /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder ProducesProblem(this MinimalActionEndpointConventionBuilder builder, + /// A that can be used to further customize the endpoint. + public static DelegateEndpointConventionBuilder ProducesProblem(this DelegateEndpointConventionBuilder builder, int statusCode, string? contentType = null) { @@ -109,11 +105,11 @@ public static MinimalActionEndpointConventionBuilder ProducesProblem(this Minima /// Adds the with a type /// to for all builders produced by . /// - /// The . + /// The . /// The response status code. Defaults to StatusCodes.Status400BadRequest. /// The response content type. Defaults to "application/validationproblem+json". - /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder ProducesValidationProblem(this MinimalActionEndpointConventionBuilder builder, + /// A that can be used to further customize the endpoint. + public static DelegateEndpointConventionBuilder ProducesValidationProblem(this DelegateEndpointConventionBuilder builder, int statusCode = StatusCodes.Status400BadRequest, string? contentType = null) { @@ -130,11 +126,11 @@ public static MinimalActionEndpointConventionBuilder ProducesValidationProblem(t /// produced by . /// /// The type of the request. - /// The . + /// The . /// The request content type. Defaults to "application/json" if empty. /// Additional response content types the endpoint produces for the supplied status code. - /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder Accepts(this MinimalActionEndpointConventionBuilder builder, string contentType, params string[] additionalContentTypes) + /// A that can be used to further customize the endpoint. + public static DelegateEndpointConventionBuilder Accepts(this DelegateEndpointConventionBuilder builder, string contentType, params string[] additionalContentTypes) { Accepts(builder, typeof(TRequest), contentType, additionalContentTypes); @@ -145,12 +141,12 @@ public static MinimalActionEndpointConventionBuilder Accepts(this Mini /// Adds the to for all builders /// produced by . /// - /// The . + /// The . /// The type of the request. Defaults to null. /// The response content type that the endpoint accepts. /// Additional response content types the endpoint accepts - /// A that can be used to further customize the endpoint. - public static MinimalActionEndpointConventionBuilder Accepts(this MinimalActionEndpointConventionBuilder builder, Type requestType, + /// A that can be used to further customize the endpoint. + public static DelegateEndpointConventionBuilder Accepts(this DelegateEndpointConventionBuilder builder, Type requestType, string contentType, params string[] additionalContentTypes) { builder.WithMetadata(new ConsumesAttribute(requestType, contentType, additionalContentTypes)); diff --git a/src/Mvc/Mvc.Core/src/PublicAPI.Unshipped.txt b/src/Mvc/Mvc.Core/src/PublicAPI.Unshipped.txt index 0c8597b3f152..80e9d26d26a6 100644 --- a/src/Mvc/Mvc.Core/src/PublicAPI.Unshipped.txt +++ b/src/Mvc/Mvc.Core/src/PublicAPI.Unshipped.txt @@ -545,8 +545,13 @@ Microsoft.AspNetCore.Mvc.Infrastructure.ActionDescriptorCollection.Items.get -> Microsoft.AspNetCore.Mvc.Infrastructure.AmbiguousActionException.AmbiguousActionException(System.Runtime.Serialization.SerializationInfo! info, System.Runtime.Serialization.StreamingContext context) -> void Microsoft.AspNetCore.Mvc.Infrastructure.AmbiguousActionException.AmbiguousActionException(string? message) -> void Microsoft.AspNetCore.Mvc.Infrastructure.ContentResultExecutor.ContentResultExecutor(Microsoft.Extensions.Logging.ILogger! logger, Microsoft.AspNetCore.Mvc.Infrastructure.IHttpResponseStreamWriterFactory! httpResponseStreamWriterFactory) -> void -static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.Accepts(this Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! builder, System.Type! requestType, string! contentType, params string![]! additionalContentTypes) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.Accepts(this Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! builder, string! contentType, params string![]! additionalContentTypes) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! +static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.Accepts(this Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! builder, System.Type! requestType, string! contentType, params string![]! additionalContentTypes) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.Accepts(this Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! builder, string! contentType, params string![]! additionalContentTypes) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.ExcludeFromDescription(this Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! builder) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.Produces(this Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! builder, int statusCode, System.Type? responseType = null, string? contentType = null, params string![]! additionalContentTypes) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.Produces(this Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! builder, int statusCode = 200, string? contentType = null, params string![]! additionalContentTypes) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.ProducesProblem(this Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! builder, int statusCode, string? contentType = null) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! +static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.ProducesValidationProblem(this Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! builder, int statusCode = 400, string? contentType = null) -> Microsoft.AspNetCore.Builder.DelegateEndpointConventionBuilder! ~Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector.DefaultOutputFormatterSelector(Microsoft.Extensions.Options.IOptions! options, Microsoft.Extensions.Logging.ILoggerFactory! loggerFactory) -> void Microsoft.AspNetCore.Mvc.Infrastructure.FileContentResultExecutor.FileContentResultExecutor(Microsoft.Extensions.Logging.ILoggerFactory! loggerFactory) -> void Microsoft.AspNetCore.Mvc.Infrastructure.FileResultExecutorBase.FileResultExecutorBase(Microsoft.Extensions.Logging.ILogger! logger) -> void @@ -3224,8 +3229,3 @@ virtual Microsoft.AspNetCore.Mvc.RequireHttpsAttribute.HandleNonHttpsRequest(Mic virtual Microsoft.AspNetCore.Mvc.RequireHttpsAttribute.OnAuthorization(Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext! filterContext) -> void Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute.ProducesResponseTypeAttribute(System.Type! type, int statusCode, string! contentType, params string![]! additionalContentTypes) -> void Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions -static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.ExcludeFromDescription(this Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! builder) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.Produces(this Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! builder, int statusCode = 200, string? contentType = null, params string![]! additionalContentTypes) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.Produces(this Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! builder, int statusCode, System.Type? responseType = null, string? contentType = null, params string![]! additionalContentTypes) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.ProducesProblem(this Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! builder, int statusCode, string? contentType = null) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! -static Microsoft.AspNetCore.Http.OpenApiEndpointConventionBuilderExtensions.ProducesValidationProblem(this Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! builder, int statusCode = 400, string? contentType = null) -> Microsoft.AspNetCore.Builder.MinimalActionEndpointConventionBuilder! From 86f743974960d5754c8731b6a04dab2c92748a38 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 20 Aug 2021 14:56:40 -0700 Subject: [PATCH 4/6] RequestDelegateFactory.Create(action -> handler --- .../src/PublicAPI.Unshipped.txt | 2 +- .../src/RequestDelegateFactory.cs | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Http/Http.Extensions/src/PublicAPI.Unshipped.txt b/src/Http/Http.Extensions/src/PublicAPI.Unshipped.txt index 65dc3997cc20..3e5511733340 100644 --- a/src/Http/Http.Extensions/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Extensions/src/PublicAPI.Unshipped.txt @@ -192,7 +192,7 @@ static Microsoft.AspNetCore.Http.HeaderDictionaryTypeExtensions.AppendList(th static Microsoft.AspNetCore.Http.HeaderDictionaryTypeExtensions.GetTypedHeaders(this Microsoft.AspNetCore.Http.HttpRequest! request) -> Microsoft.AspNetCore.Http.Headers.RequestHeaders! static Microsoft.AspNetCore.Http.HeaderDictionaryTypeExtensions.GetTypedHeaders(this Microsoft.AspNetCore.Http.HttpResponse! response) -> Microsoft.AspNetCore.Http.Headers.ResponseHeaders! static Microsoft.AspNetCore.Http.HttpContextServerVariableExtensions.GetServerVariable(this Microsoft.AspNetCore.Http.HttpContext! context, string! variableName) -> string? -static Microsoft.AspNetCore.Http.RequestDelegateFactory.Create(System.Delegate! action, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions? options = null) -> Microsoft.AspNetCore.Http.RequestDelegateResult! +static Microsoft.AspNetCore.Http.RequestDelegateFactory.Create(System.Delegate! handler, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions? options = null) -> Microsoft.AspNetCore.Http.RequestDelegateResult! static Microsoft.AspNetCore.Http.RequestDelegateFactory.Create(System.Reflection.MethodInfo! methodInfo, System.Func? targetFactory = null, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions? options = null) -> Microsoft.AspNetCore.Http.RequestDelegateResult! static Microsoft.AspNetCore.Http.ResponseExtensions.Clear(this Microsoft.AspNetCore.Http.HttpResponse! response) -> void static Microsoft.AspNetCore.Http.ResponseExtensions.Redirect(this Microsoft.AspNetCore.Http.HttpResponse! response, string! location, bool permanent, bool preserveMethod) -> void diff --git a/src/Http/Http.Extensions/src/RequestDelegateFactory.cs b/src/Http/Http.Extensions/src/RequestDelegateFactory.cs index eb6a6eebe06f..cb2bc5d44cc1 100644 --- a/src/Http/Http.Extensions/src/RequestDelegateFactory.cs +++ b/src/Http/Http.Extensions/src/RequestDelegateFactory.cs @@ -67,23 +67,23 @@ public static partial class RequestDelegateFactory private static readonly AcceptsMetadata DefaultAcceptsMetadata = new(new[] { "application/json" }); /// - /// Creates a implementation for . + /// Creates a implementation for . /// - /// A request handler with any number of custom parameters that often produces a response with its return value. + /// A request handler with any number of custom parameters that often produces a response with its return value. /// The used to configure the behavior of the handler. /// The . #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters - public static RequestDelegateResult Create(Delegate action, RequestDelegateFactoryOptions? options = null) + public static RequestDelegateResult Create(Delegate handler, RequestDelegateFactoryOptions? options = null) #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters { - if (action is null) + if (handler is null) { - throw new ArgumentNullException(nameof(action)); + throw new ArgumentNullException(nameof(handler)); } - var targetExpression = action.Target switch + var targetExpression = handler.Target switch { - object => Expression.Convert(TargetExpr, action.Target.GetType()), + object => Expression.Convert(TargetExpr, handler.Target.GetType()), null => null, }; @@ -92,9 +92,9 @@ public static RequestDelegateResult Create(Delegate action, RequestDelegateFacto ServiceProviderIsService = options?.ServiceProvider?.GetService() }; - var targetableRequestDelegate = CreateTargetableRequestDelegate(action.Method, options, factoryContext, targetExpression); + var targetableRequestDelegate = CreateTargetableRequestDelegate(handler.Method, options, factoryContext, targetExpression); - return new RequestDelegateResult(httpContext => targetableRequestDelegate(action.Target, httpContext), factoryContext.Metadata); + return new RequestDelegateResult(httpContext => targetableRequestDelegate(handler.Target, httpContext), factoryContext.Metadata); } @@ -149,14 +149,14 @@ public static RequestDelegateResult Create(MethodInfo methodInfo, Func(action(..), httpContext); + // ExecuteTask(handler(..), httpContext); else if (typeArg == typeof(string)) { return Expression.Call( @@ -459,7 +459,7 @@ private static Expression AddResponseWritingToMethodCall(Expression methodCall, methodCall, HttpContextExpr); } - // ExecuteTask(action(..), httpContext); + // ExecuteTask(handler(..), httpContext); else if (typeArg == typeof(string)) { return Expression.Call( From 72c939e2b4c997f0a7a36045fae27c87b6414c80 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 20 Aug 2021 15:46:41 -0700 Subject: [PATCH 5/6] MinimalActions -> DelegateEndpoints in analyzer --- .../DelegateEndpointAnalyzer.cs} | 12 ++++++------ .../DiagnosticDescriptors.cs | 8 ++++---- .../DisallowMvcBindArgumentsOnParameters.cs | 6 +++--- .../WellKnownTypes.cs | 10 +++++----- .../{MapDelegateTest.cs => DelegateEndpointTest.cs} | 6 +----- 5 files changed, 19 insertions(+), 23 deletions(-) rename src/Framework/Analyzer/src/{MinimalActions/MinimalActionAnalyzer.cs => DelegateEndpoints/DelegateEndpointAnalyzer.cs} (85%) rename src/Framework/Analyzer/src/{MinimalActions => DelegateEndpoints}/DiagnosticDescriptors.cs (71%) rename src/Framework/Analyzer/src/{MinimalActions => DelegateEndpoints}/DisallowMvcBindArgumentsOnParameters.cs (90%) rename src/Framework/Analyzer/src/{MinimalActions => DelegateEndpoints}/WellKnownTypes.cs (72%) rename src/Http/Routing/test/FunctionalTests/{MapDelegateTest.cs => DelegateEndpointTest.cs} (94%) diff --git a/src/Framework/Analyzer/src/MinimalActions/MinimalActionAnalyzer.cs b/src/Framework/Analyzer/src/DelegateEndpoints/DelegateEndpointAnalyzer.cs similarity index 85% rename from src/Framework/Analyzer/src/MinimalActions/MinimalActionAnalyzer.cs rename to src/Framework/Analyzer/src/DelegateEndpoints/DelegateEndpointAnalyzer.cs index c5640e170af6..ad712b22ef1f 100644 --- a/src/Framework/Analyzer/src/MinimalActions/MinimalActionAnalyzer.cs +++ b/src/Framework/Analyzer/src/DelegateEndpoints/DelegateEndpointAnalyzer.cs @@ -8,14 +8,14 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Operations; -namespace Microsoft.AspNetCore.Analyzers.MinimalActions; +namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints; [DiagnosticAnalyzer(LanguageNames.CSharp)] -public partial class MinimalActionAnalyzer : DiagnosticAnalyzer +public partial class DelegateEndpointAnalyzer : DiagnosticAnalyzer { public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(new[] { - DiagnosticDescriptors.DoNotUseModelBindingAttributesOnMinimalActionParameters, + DiagnosticDescriptors.DoNotUseModelBindingAttributesOnDelegateEndpointParameters, }); public override void Initialize(AnalysisContext context) @@ -35,7 +35,7 @@ public override void Initialize(AnalysisContext context) { var invocation = (IInvocationOperation)operationAnalysisContext.Operation; var targetMethod = invocation.TargetMethod; - if (IsMapActionInvocation(wellKnownTypes, invocation, targetMethod)) + if (IsDelegateHandlerInvocation(wellKnownTypes, invocation, targetMethod)) { return; } @@ -60,13 +60,13 @@ public override void Initialize(AnalysisContext context) }); } - private static bool IsMapActionInvocation( + private static bool IsDelegateHandlerInvocation( WellKnownTypes wellKnownTypes, IInvocationOperation invocation, IMethodSymbol targetMethod) { return !targetMethod.Name.StartsWith("Map", StringComparison.Ordinal) || - !SymbolEqualityComparer.Default.Equals(wellKnownTypes.MinimalActionEndpointRouteBuilderExtensions, targetMethod.ContainingType) || + !SymbolEqualityComparer.Default.Equals(wellKnownTypes.DelegateEndpointRouteBuilderExtensions, targetMethod.ContainingType) || invocation.Arguments.Length != 3; } } diff --git a/src/Framework/Analyzer/src/MinimalActions/DiagnosticDescriptors.cs b/src/Framework/Analyzer/src/DelegateEndpoints/DiagnosticDescriptors.cs similarity index 71% rename from src/Framework/Analyzer/src/MinimalActions/DiagnosticDescriptors.cs rename to src/Framework/Analyzer/src/DelegateEndpoints/DiagnosticDescriptors.cs index c4b2fb99f06f..2a133e2c1627 100644 --- a/src/Framework/Analyzer/src/MinimalActions/DiagnosticDescriptors.cs +++ b/src/Framework/Analyzer/src/DelegateEndpoints/DiagnosticDescriptors.cs @@ -3,15 +3,15 @@ using Microsoft.CodeAnalysis; -namespace Microsoft.AspNetCore.Analyzers.MinimalActions +namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints { [System.Diagnostics.CodeAnalysis.SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking")] internal static class DiagnosticDescriptors { - internal static readonly DiagnosticDescriptor DoNotUseModelBindingAttributesOnMinimalActionParameters = new( + internal static readonly DiagnosticDescriptor DoNotUseModelBindingAttributesOnDelegateEndpointParameters = new( "ASP0003", - "Do not use model binding attributes with Map actions", - "{0} should not be specified for a {1} delegate parameter", + "Do not use model binding attributes with Map handlers", + "{0} should not be specified for a {1} Delegate parameter", "Usage", DiagnosticSeverity.Warning, isEnabledByDefault: true, diff --git a/src/Framework/Analyzer/src/MinimalActions/DisallowMvcBindArgumentsOnParameters.cs b/src/Framework/Analyzer/src/DelegateEndpoints/DisallowMvcBindArgumentsOnParameters.cs similarity index 90% rename from src/Framework/Analyzer/src/MinimalActions/DisallowMvcBindArgumentsOnParameters.cs rename to src/Framework/Analyzer/src/DelegateEndpoints/DisallowMvcBindArgumentsOnParameters.cs index 80fbd5534651..19636859c22b 100644 --- a/src/Framework/Analyzer/src/MinimalActions/DisallowMvcBindArgumentsOnParameters.cs +++ b/src/Framework/Analyzer/src/DelegateEndpoints/DisallowMvcBindArgumentsOnParameters.cs @@ -6,9 +6,9 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Operations; -namespace Microsoft.AspNetCore.Analyzers.MinimalActions; +namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints; -public partial class MinimalActionAnalyzer : DiagnosticAnalyzer +public partial class DelegateEndpointAnalyzer : DiagnosticAnalyzer { private static void DisallowMvcBindArgumentsOnParameters( in OperationAnalysisContext context, @@ -33,7 +33,7 @@ private static void DisallowMvcBindArgumentsOnParameters( var methodName = invocation.TargetMethod.Name; context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.DoNotUseModelBindingAttributesOnMinimalActionParameters, + DiagnosticDescriptors.DoNotUseModelBindingAttributesOnDelegateEndpointParameters, location, modelBindingAttribute.AttributeClass.Name, methodName)); diff --git a/src/Framework/Analyzer/src/MinimalActions/WellKnownTypes.cs b/src/Framework/Analyzer/src/DelegateEndpoints/WellKnownTypes.cs similarity index 72% rename from src/Framework/Analyzer/src/MinimalActions/WellKnownTypes.cs rename to src/Framework/Analyzer/src/DelegateEndpoints/WellKnownTypes.cs index 4ef66bb80bb3..2576e56b6a4c 100644 --- a/src/Framework/Analyzer/src/MinimalActions/WellKnownTypes.cs +++ b/src/Framework/Analyzer/src/DelegateEndpoints/WellKnownTypes.cs @@ -4,15 +4,15 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis; -namespace Microsoft.AspNetCore.Analyzers.MinimalActions; +namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints; internal sealed class WellKnownTypes { public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out WellKnownTypes? wellKnownTypes) { wellKnownTypes = default; - const string MinimalActionEndpointRouteBuilderExtensions = "Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions"; - if (compilation.GetTypeByMetadataName(MinimalActionEndpointRouteBuilderExtensions) is not { } minimalActionEndpointRouteBuilderExtensions) + const string DelegateEndpointRouteBuilderExtensions = "Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions"; + if (compilation.GetTypeByMetadataName(DelegateEndpointRouteBuilderExtensions) is not { } delegateEndpointRouteBuilderExtensions) { return false; } @@ -33,7 +33,7 @@ public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out We wellKnownTypes = new WellKnownTypes { - MinimalActionEndpointRouteBuilderExtensions = minimalActionEndpointRouteBuilderExtensions, + DelegateEndpointRouteBuilderExtensions = delegateEndpointRouteBuilderExtensions, IBinderTypeProviderMetadata = ibinderTypeProviderMetadata, BindAttribute = bindAttribute, }; @@ -41,7 +41,7 @@ public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out We return true; } - public ITypeSymbol MinimalActionEndpointRouteBuilderExtensions { get; private init; } + public ITypeSymbol DelegateEndpointRouteBuilderExtensions { get; private init; } public INamedTypeSymbol IBinderTypeProviderMetadata { get; private init; } public INamedTypeSymbol BindAttribute { get; private init; } } diff --git a/src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs b/src/Http/Routing/test/FunctionalTests/DelegateEndpointTest.cs similarity index 94% rename from src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs rename to src/Http/Routing/test/FunctionalTests/DelegateEndpointTest.cs index 690cb236e346..a79195788be8 100644 --- a/src/Http/Routing/test/FunctionalTests/MapDelegateTest.cs +++ b/src/Http/Routing/test/FunctionalTests/DelegateEndpointTest.cs @@ -3,21 +3,17 @@ #nullable enable -using System; using System.Net.Http.Json; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Xunit; namespace Microsoft.AspNetCore.Routing.FunctionalTests { - public class MapDelegateTest + public class DelegateEndpointTest { [Fact] public async Task MapPost_FromBodyWorksWithJsonPayload() From 3b2ae74dc75255fea755e2e03fd17413488332ab Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 20 Aug 2021 16:25:37 -0700 Subject: [PATCH 6/6] Fix test `action:` -> `handler:` --- src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs b/src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs index 4dc8330792b4..631e6c0b886f 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs @@ -185,10 +185,10 @@ public void BuildRequestDelegateThrowsArgumentNullExceptions() var serviceProvider = new EmptyServiceProvider(); - var exNullAction = Assert.Throws(() => RequestDelegateFactory.Create(action: null!)); + var exNullAction = Assert.Throws(() => RequestDelegateFactory.Create(handler: null!)); var exNullMethodInfo1 = Assert.Throws(() => RequestDelegateFactory.Create(methodInfo: null!)); - Assert.Equal("action", exNullAction.ParamName); + Assert.Equal("handler", exNullAction.ParamName); Assert.Equal("methodInfo", exNullMethodInfo1.ParamName); }