Rename UseEndpointRouting to UseRouting (#4416)
This commit is contained in:
parent
00cf0a4d7d
commit
a07be53033
|
|
@ -32,7 +32,7 @@ namespace MvcSandbox
|
|||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseEndpointRouting(builder =>
|
||||
app.UseRouting(builder =>
|
||||
{
|
||||
builder.MapGet(
|
||||
requestDelegate: WriteEndpoints,
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
{
|
||||
// Matching middleware has not been registered yet
|
||||
// For back-compat register middleware so an endpoint is matched and then immediately used
|
||||
app.UseEndpointRouting(routerBuilder =>
|
||||
app.UseRouting(routerBuilder =>
|
||||
{
|
||||
routerBuilder.DataSources.Add(mvcEndpointDataSource);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Benchmarks
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseEndpointRouting(builder =>
|
||||
app.UseRouting(builder =>
|
||||
{
|
||||
var endpointDataSource = new DefaultEndpointDataSource(new[]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -43,4 +43,4 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(DotNetPackageVersionPropsPath)" Condition=" '$(DotNetPackageVersionPropsPath)' != '' " />
|
||||
<PropertyGroup Label="Package Versions: Pinned" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -31,7 +31,7 @@ namespace RoutingSandbox
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseEndpointRouting(builder =>
|
||||
app.UseRouting(builder =>
|
||||
{
|
||||
builder.MapHello("/helloworld", "World");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -14,8 +14,20 @@ namespace Microsoft.AspNetCore.Builder
|
|||
// Property key is used by MVC package to check that routing is registered
|
||||
private const string EndpointRoutingRegisteredKey = "__EndpointRoutingMiddlewareRegistered";
|
||||
|
||||
public static IApplicationBuilder UseEndpointRouting(this IApplicationBuilder builder, Action<IEndpointRouteBuilder> configure)
|
||||
/// <summary>
|
||||
/// Adds a <see cref="EndpointRoutingMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>
|
||||
/// with the <see cref="EndpointDataSource"/> instances built from configured <see cref="IEndpointRouteBuilder"/>.
|
||||
/// </summary>
|
||||
/// <param name="builder">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
||||
/// <param name="configure">An <see cref="Action{IEndpointRouteBuilder}"/> to configure the provided <see cref="IEndpointRouteBuilder"/>.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IApplicationBuilder UseRouting(this IApplicationBuilder builder, Action<IEndpointRouteBuilder> configure)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (configure == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(configure));
|
||||
|
|
@ -46,14 +58,24 @@ namespace Microsoft.AspNetCore.Builder
|
|||
return builder.UseMiddleware<EndpointRoutingMiddleware>(middlewareEndpointDataSource);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="EndpointMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>.
|
||||
/// </summary>
|
||||
/// <param name="builder">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IApplicationBuilder UseEndpoint(this IApplicationBuilder builder)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
VerifyRoutingIsRegistered(builder);
|
||||
|
||||
if (!builder.Properties.TryGetValue(EndpointRoutingRegisteredKey, out _))
|
||||
{
|
||||
var message = $"{nameof(EndpointRoutingMiddleware)} must be added to the request execution pipeline before {nameof(EndpointMiddleware)}. " +
|
||||
$"Please add {nameof(EndpointRoutingMiddleware)} by calling '{nameof(IApplicationBuilder)}.{nameof(UseEndpointRouting)}' inside the call to 'Configure(...)' in the application startup code.";
|
||||
$"Please add {nameof(EndpointRoutingMiddleware)} by calling '{nameof(IApplicationBuilder)}.{nameof(UseRouting)}' inside the call to 'Configure(...)' in the application startup code.";
|
||||
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
|
@ -74,4 +96,4 @@ namespace Microsoft.AspNetCore.Builder
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -21,13 +21,13 @@ namespace Microsoft.AspNetCore.Builder
|
|||
public class EndpointRoutingApplicationBuilderExtensionsTest
|
||||
{
|
||||
[Fact]
|
||||
public void UseEndpointRouting_ServicesNotRegistered_Throws()
|
||||
public void UseRouting_ServicesNotRegistered_Throws()
|
||||
{
|
||||
// Arrange
|
||||
var app = new ApplicationBuilder(Mock.Of<IServiceProvider>());
|
||||
|
||||
// Act
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => app.UseEndpointRouting(builder => { }));
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => app.UseRouting(builder => { }));
|
||||
|
||||
// Assert
|
||||
Assert.Equal(
|
||||
|
|
@ -55,14 +55,14 @@ namespace Microsoft.AspNetCore.Builder
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UseEndpointRouting_ServicesRegistered_NoMatch_DoesNotSetFeature()
|
||||
public async Task UseRouting_ServicesRegistered_NoMatch_DoesNotSetFeature()
|
||||
{
|
||||
// Arrange
|
||||
var services = CreateServices();
|
||||
|
||||
var app = new ApplicationBuilder(services);
|
||||
|
||||
app.UseEndpointRouting(builder => { });
|
||||
app.UseRouting(builder => { });
|
||||
|
||||
var appFunc = app.Build();
|
||||
var httpContext = new DefaultHttpContext();
|
||||
|
|
@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UseEndpointRouting_ServicesRegistered_Match_DoesNotSetsFeature()
|
||||
public async Task UseRouting_ServicesRegistered_Match_DoesNotSetsFeature()
|
||||
{
|
||||
// Arrange
|
||||
var endpoint = new RouteEndpoint(
|
||||
|
|
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
|
||||
var app = new ApplicationBuilder(services);
|
||||
|
||||
app.UseEndpointRouting(builder =>
|
||||
app.UseRouting(builder =>
|
||||
{
|
||||
builder.DataSources.Add(new DefaultEndpointDataSource(endpoint));
|
||||
});
|
||||
|
|
@ -133,7 +133,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
|
||||
var app = new ApplicationBuilder(services);
|
||||
|
||||
app.UseEndpointRouting(builder => { });
|
||||
app.UseRouting(builder => { });
|
||||
app.UseEndpoint();
|
||||
|
||||
var appFunc = app.Build();
|
||||
|
|
@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void UseEndpointRouting_CallWithBuilder_SetsEndpointDataSource()
|
||||
public void UseRouting_CallWithBuilder_SetsEndpointDataSource()
|
||||
{
|
||||
// Arrange
|
||||
var matcherEndpointDataSources = new List<EndpointDataSource>();
|
||||
|
|
@ -165,13 +165,13 @@ namespace Microsoft.AspNetCore.Builder
|
|||
var app = new ApplicationBuilder(services);
|
||||
|
||||
// Act
|
||||
app.UseEndpointRouting(builder =>
|
||||
app.UseRouting(builder =>
|
||||
{
|
||||
builder.Map("/1", "Test endpoint 1", d => null);
|
||||
builder.Map("/2", "Test endpoint 2", d => null);
|
||||
});
|
||||
|
||||
app.UseEndpointRouting(builder =>
|
||||
app.UseRouting(builder =>
|
||||
{
|
||||
builder.Map("/3", "Test endpoint 3", d => null);
|
||||
builder.Map("/4", "Test endpoint 4", d => null);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -35,7 +35,7 @@ namespace RoutingWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseEndpointRouting(routes =>
|
||||
app.UseRouting(routes =>
|
||||
{
|
||||
routes.MapHello("/helloworld", "World");
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ namespace RoutingWebSite
|
|||
|
||||
private void SetupBranch(IApplicationBuilder app, string name)
|
||||
{
|
||||
app.UseEndpointRouting(routes =>
|
||||
app.UseRouting(routes =>
|
||||
{
|
||||
routes.MapGet("api/get/{id}", (context) => context.Response.WriteAsync($"{name} - API Get {context.GetRouteData().Values["id"]}"));
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue