Skip to content

Commit 4d7a852

Browse files
halter73Pilchie
authored andcommitted
Minimal APIs naming cleanup
1 parent 8829b16 commit 4d7a852

15 files changed

+133
-142
lines changed

src/Framework/Analyzer/src/MinimalActions/MinimalActionAnalyzer.cs renamed to src/Framework/Analyzer/src/DelegateEndpoints/DelegateEndpointAnalyzer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
using Microsoft.CodeAnalysis.Diagnostics;
99
using Microsoft.CodeAnalysis.Operations;
1010

11-
namespace Microsoft.AspNetCore.Analyzers.MinimalActions;
11+
namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints;
1212

1313
[DiagnosticAnalyzer(LanguageNames.CSharp)]
14-
public partial class MinimalActionAnalyzer : DiagnosticAnalyzer
14+
public partial class DelegateEndpointAnalyzer : DiagnosticAnalyzer
1515
{
1616
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(new[]
1717
{
18-
DiagnosticDescriptors.DoNotUseModelBindingAttributesOnMinimalActionParameters,
18+
DiagnosticDescriptors.DoNotUseModelBindingAttributesOnDelegateEndpointParameters,
1919
});
2020

2121
public override void Initialize(AnalysisContext context)
@@ -35,7 +35,7 @@ public override void Initialize(AnalysisContext context)
3535
{
3636
var invocation = (IInvocationOperation)operationAnalysisContext.Operation;
3737
var targetMethod = invocation.TargetMethod;
38-
if (IsMapActionInvocation(wellKnownTypes, invocation, targetMethod))
38+
if (IsDelegateHandlerInvocation(wellKnownTypes, invocation, targetMethod))
3939
{
4040
return;
4141
}
@@ -60,13 +60,13 @@ public override void Initialize(AnalysisContext context)
6060
});
6161
}
6262

63-
private static bool IsMapActionInvocation(
63+
private static bool IsDelegateHandlerInvocation(
6464
WellKnownTypes wellKnownTypes,
6565
IInvocationOperation invocation,
6666
IMethodSymbol targetMethod)
6767
{
6868
return !targetMethod.Name.StartsWith("Map", StringComparison.Ordinal) ||
69-
!SymbolEqualityComparer.Default.Equals(wellKnownTypes.MinimalActionEndpointRouteBuilderExtensions, targetMethod.ContainingType) ||
69+
!SymbolEqualityComparer.Default.Equals(wellKnownTypes.DelegateEndpointRouteBuilderExtensions, targetMethod.ContainingType) ||
7070
invocation.Arguments.Length != 3;
7171
}
7272
}

src/Framework/Analyzer/src/MinimalActions/DiagnosticDescriptors.cs renamed to src/Framework/Analyzer/src/DelegateEndpoints/DiagnosticDescriptors.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
using Microsoft.CodeAnalysis;
55

6-
namespace Microsoft.AspNetCore.Analyzers.MinimalActions
6+
namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints
77
{
88
[System.Diagnostics.CodeAnalysis.SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking")]
99
internal static class DiagnosticDescriptors
1010
{
11-
internal static readonly DiagnosticDescriptor DoNotUseModelBindingAttributesOnMinimalActionParameters = new(
11+
internal static readonly DiagnosticDescriptor DoNotUseModelBindingAttributesOnDelegateEndpointParameters = new(
1212
"ASP0003",
13-
"Do not use model binding attributes with Map actions",
14-
"{0} should not be specified for a {1} delegate parameter",
13+
"Do not use model binding attributes with Map handlers",
14+
"{0} should not be specified for a {1} Delegate parameter",
1515
"Usage",
1616
DiagnosticSeverity.Warning,
1717
isEnabledByDefault: true,

src/Framework/Analyzer/src/MinimalActions/DisallowMvcBindArgumentsOnParameters.cs renamed to src/Framework/Analyzer/src/DelegateEndpoints/DisallowMvcBindArgumentsOnParameters.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
using Microsoft.CodeAnalysis.Diagnostics;
77
using Microsoft.CodeAnalysis.Operations;
88

9-
namespace Microsoft.AspNetCore.Analyzers.MinimalActions;
9+
namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints;
1010

11-
public partial class MinimalActionAnalyzer : DiagnosticAnalyzer
11+
public partial class DelegateEndpointAnalyzer : DiagnosticAnalyzer
1212
{
1313
private static void DisallowMvcBindArgumentsOnParameters(
1414
in OperationAnalysisContext context,
@@ -33,7 +33,7 @@ private static void DisallowMvcBindArgumentsOnParameters(
3333
var methodName = invocation.TargetMethod.Name;
3434

3535
context.ReportDiagnostic(Diagnostic.Create(
36-
DiagnosticDescriptors.DoNotUseModelBindingAttributesOnMinimalActionParameters,
36+
DiagnosticDescriptors.DoNotUseModelBindingAttributesOnDelegateEndpointParameters,
3737
location,
3838
modelBindingAttribute.AttributeClass.Name,
3939
methodName));

src/Framework/Analyzer/src/MinimalActions/WellKnownTypes.cs renamed to src/Framework/Analyzer/src/DelegateEndpoints/WellKnownTypes.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
using System.Diagnostics.CodeAnalysis;
55
using Microsoft.CodeAnalysis;
66

7-
namespace Microsoft.AspNetCore.Analyzers.MinimalActions;
7+
namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints;
88

99
internal sealed class WellKnownTypes
1010
{
1111
public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out WellKnownTypes? wellKnownTypes)
1212
{
1313
wellKnownTypes = default;
14-
const string MinimalActionEndpointRouteBuilderExtensions = "Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions";
15-
if (compilation.GetTypeByMetadataName(MinimalActionEndpointRouteBuilderExtensions) is not { } minimalActionEndpointRouteBuilderExtensions)
14+
const string DelegateEndpointRouteBuilderExtensions = "Microsoft.AspNetCore.Builder.DelegateEndpointRouteBuilderExtensions";
15+
if (compilation.GetTypeByMetadataName(DelegateEndpointRouteBuilderExtensions) is not { } delegateEndpointRouteBuilderExtensions)
1616
{
1717
return false;
1818
}
@@ -33,15 +33,15 @@ public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out We
3333

3434
wellKnownTypes = new WellKnownTypes
3535
{
36-
MinimalActionEndpointRouteBuilderExtensions = minimalActionEndpointRouteBuilderExtensions,
36+
DelegateEndpointRouteBuilderExtensions = delegateEndpointRouteBuilderExtensions,
3737
IBinderTypeProviderMetadata = ibinderTypeProviderMetadata,
3838
BindAttribute = bindAttribute,
3939
};
4040

4141
return true;
4242
}
4343

44-
public ITypeSymbol MinimalActionEndpointRouteBuilderExtensions { get; private init; }
44+
public ITypeSymbol DelegateEndpointRouteBuilderExtensions { get; private init; }
4545
public INamedTypeSymbol IBinderTypeProviderMetadata { get; private init; }
4646
public INamedTypeSymbol BindAttribute { get; private init; }
4747
}

src/Http/Http.Extensions/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static Microsoft.AspNetCore.Http.HeaderDictionaryTypeExtensions.AppendList<T>(th
192192
static Microsoft.AspNetCore.Http.HeaderDictionaryTypeExtensions.GetTypedHeaders(this Microsoft.AspNetCore.Http.HttpRequest! request) -> Microsoft.AspNetCore.Http.Headers.RequestHeaders!
193193
static Microsoft.AspNetCore.Http.HeaderDictionaryTypeExtensions.GetTypedHeaders(this Microsoft.AspNetCore.Http.HttpResponse! response) -> Microsoft.AspNetCore.Http.Headers.ResponseHeaders!
194194
static Microsoft.AspNetCore.Http.HttpContextServerVariableExtensions.GetServerVariable(this Microsoft.AspNetCore.Http.HttpContext! context, string! variableName) -> string?
195-
static Microsoft.AspNetCore.Http.RequestDelegateFactory.Create(System.Delegate! action, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions? options = null) -> Microsoft.AspNetCore.Http.RequestDelegateResult!
195+
static Microsoft.AspNetCore.Http.RequestDelegateFactory.Create(System.Delegate! handler, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions? options = null) -> Microsoft.AspNetCore.Http.RequestDelegateResult!
196196
static Microsoft.AspNetCore.Http.RequestDelegateFactory.Create(System.Reflection.MethodInfo! methodInfo, System.Func<Microsoft.AspNetCore.Http.HttpContext!, object!>? targetFactory = null, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions? options = null) -> Microsoft.AspNetCore.Http.RequestDelegateResult!
197197
static Microsoft.AspNetCore.Http.ResponseExtensions.Clear(this Microsoft.AspNetCore.Http.HttpResponse! response) -> void
198198
static Microsoft.AspNetCore.Http.ResponseExtensions.Redirect(this Microsoft.AspNetCore.Http.HttpResponse! response, string! location, bool permanent, bool preserveMethod) -> void

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,23 @@ public static partial class RequestDelegateFactory
6767
private static readonly AcceptsMetadata DefaultAcceptsMetadata = new(new[] { "application/json" });
6868

6969
/// <summary>
70-
/// Creates a <see cref="RequestDelegate"/> implementation for <paramref name="action"/>.
70+
/// Creates a <see cref="RequestDelegate"/> implementation for <paramref name="handler"/>.
7171
/// </summary>
72-
/// <param name="action">A request handler with any number of custom parameters that often produces a response with its return value.</param>
72+
/// <param name="handler">A request handler with any number of custom parameters that often produces a response with its return value.</param>
7373
/// <param name="options">The <see cref="RequestDelegateFactoryOptions"/> used to configure the behavior of the handler.</param>
7474
/// <returns>The <see cref="RequestDelegateResult"/>.</returns>
7575
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
76-
public static RequestDelegateResult Create(Delegate action, RequestDelegateFactoryOptions? options = null)
76+
public static RequestDelegateResult Create(Delegate handler, RequestDelegateFactoryOptions? options = null)
7777
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters
7878
{
79-
if (action is null)
79+
if (handler is null)
8080
{
81-
throw new ArgumentNullException(nameof(action));
81+
throw new ArgumentNullException(nameof(handler));
8282
}
8383

84-
var targetExpression = action.Target switch
84+
var targetExpression = handler.Target switch
8585
{
86-
object => Expression.Convert(TargetExpr, action.Target.GetType()),
86+
object => Expression.Convert(TargetExpr, handler.Target.GetType()),
8787
null => null,
8888
};
8989

@@ -92,9 +92,9 @@ public static RequestDelegateResult Create(Delegate action, RequestDelegateFacto
9292
ServiceProviderIsService = options?.ServiceProvider?.GetService<IServiceProviderIsService>()
9393
};
9494

95-
var targetableRequestDelegate = CreateTargetableRequestDelegate(action.Method, options, factoryContext, targetExpression);
95+
var targetableRequestDelegate = CreateTargetableRequestDelegate(handler.Method, options, factoryContext, targetExpression);
9696

97-
return new RequestDelegateResult(httpContext => targetableRequestDelegate(action.Target, httpContext), factoryContext.Metadata);
97+
return new RequestDelegateResult(httpContext => targetableRequestDelegate(handler.Target, httpContext), factoryContext.Metadata);
9898

9999
}
100100

@@ -149,14 +149,14 @@ public static RequestDelegateResult Create(MethodInfo methodInfo, Func<HttpConte
149149
// Task Invoke(HttpContext httpContext)
150150
// {
151151
// // Action parameters are bound from the request, services, etc... based on attribute and type information.
152-
// return ExecuteTask(action(...), httpContext);
152+
// return ExecuteTask(handler(...), httpContext);
153153
// }
154154

155155
// void return type
156156

157157
// Task Invoke(HttpContext httpContext)
158158
// {
159-
// action(...);
159+
// handler(...);
160160
// return default;
161161
// }
162162

@@ -351,7 +351,7 @@ private static Expression CreateParamCheckingResponseWritingMethodCall(
351351
// return Task.CompletedTask;
352352
// } :
353353
// {
354-
// // Logic generated by AddResponseWritingToMethodCall() that calls action(param1_local, param2_local, ...)
354+
// // Logic generated by AddResponseWritingToMethodCall() that calls handler(param1_local, param2_local, ...)
355355
// };
356356
// }
357357

@@ -431,7 +431,7 @@ private static Expression AddResponseWritingToMethodCall(Expression methodCall,
431431
methodCall,
432432
HttpContextExpr);
433433
}
434-
// ExecuteTask<T>(action(..), httpContext);
434+
// ExecuteTask<T>(handler(..), httpContext);
435435
else if (typeArg == typeof(string))
436436
{
437437
return Expression.Call(
@@ -459,7 +459,7 @@ private static Expression AddResponseWritingToMethodCall(Expression methodCall,
459459
methodCall,
460460
HttpContextExpr);
461461
}
462-
// ExecuteTask<T>(action(..), httpContext);
462+
// ExecuteTask<T>(handler(..), httpContext);
463463
else if (typeArg == typeof(string))
464464
{
465465
return Expression.Call(

src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ public void BuildRequestDelegateThrowsArgumentNullExceptions()
185185

186186
var serviceProvider = new EmptyServiceProvider();
187187

188-
var exNullAction = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(action: null!));
188+
var exNullAction = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(handler: null!));
189189
var exNullMethodInfo1 = Assert.Throws<ArgumentNullException>(() => RequestDelegateFactory.Create(methodInfo: null!));
190190

191-
Assert.Equal("action", exNullAction.ParamName);
191+
Assert.Equal("handler", exNullAction.ParamName);
192192
Assert.Equal("methodInfo", exNullMethodInfo1.ParamName);
193193
}
194194

src/Http/Routing/src/Builder/MinimalActionEndpointConventionBuilder.cs renamed to src/Http/Routing/src/Builder/DelegateEndpointConventionBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ namespace Microsoft.AspNetCore.Builder
99
/// <summary>
1010
/// Builds conventions that will be used for customization of MapAction <see cref="EndpointBuilder"/> instances.
1111
/// </summary>
12-
public sealed class MinimalActionEndpointConventionBuilder : IEndpointConventionBuilder
12+
public sealed class DelegateEndpointConventionBuilder : IEndpointConventionBuilder
1313
{
1414
private readonly List<IEndpointConventionBuilder> _endpointConventionBuilders;
1515

16-
internal MinimalActionEndpointConventionBuilder(IEndpointConventionBuilder endpointConventionBuilder)
16+
internal DelegateEndpointConventionBuilder(IEndpointConventionBuilder endpointConventionBuilder)
1717
{
1818
_endpointConventionBuilders = new List<IEndpointConventionBuilder>() { endpointConventionBuilder };
1919
}
2020

21-
internal MinimalActionEndpointConventionBuilder(List<IEndpointConventionBuilder> endpointConventionBuilders)
21+
internal DelegateEndpointConventionBuilder(List<IEndpointConventionBuilder> endpointConventionBuilders)
2222
{
2323
_endpointConventionBuilders = endpointConventionBuilders;
2424
}

0 commit comments

Comments
 (0)