Rename global routing to endpoint routing (#8179)

This commit is contained in:
James Newton-King 2018-08-01 15:05:49 +12:00 committed by GitHub
parent 0726b8b98b
commit 046af405b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 53 additions and 48 deletions

View File

@ -18,8 +18,8 @@ namespace Microsoft.AspNetCore.Builder
/// </summary>
public static class MvcApplicationBuilderExtensions
{
// Property key set in routing package by UseGlobalRouting to indicate middleware is registered
private const string GlobalRoutingRegisteredKey = "__GlobalRoutingMiddlewareRegistered";
// Property key set in routing package by UseEndpointRouting to indicate middleware is registered
private const string EndpointRoutingRegisteredKey = "__EndpointRoutingMiddlewareRegistered";
/// <summary>
/// Adds MVC to the <see cref="IApplicationBuilder"/> request execution pipeline.
@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Builder
var options = app.ApplicationServices.GetRequiredService<IOptions<MvcOptions>>();
if (options.Value.EnableGlobalRouting)
if (options.Value.EnableEndpointRouting)
{
var mvcEndpointDataSource = app.ApplicationServices
.GetRequiredService<IEnumerable<EndpointDataSource>>()
@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Builder
}
}
if (!app.Properties.TryGetValue(GlobalRoutingRegisteredKey, out _))
if (!app.Properties.TryGetValue(EndpointRoutingRegisteredKey, out _))
{
// Matching middleware has not been registered yet
// For back-compat register middleware so an endpoint is matched and then immediately used

View File

@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
if (Version >= CompatibilityVersion.Version_2_2)
{
values[nameof(MvcOptions.EnableGlobalRouting)] = true;
values[nameof(MvcOptions.EnableEndpointRouting)] = true;
}
return values;

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc
private readonly CompatibilitySwitch<bool> _allowValidatingTopLevelNodes;
private readonly CompatibilitySwitch<InputFormatterExceptionPolicy> _inputFormatterExceptionPolicy;
private readonly CompatibilitySwitch<bool> _suppressBindingUndefinedValueToEnumType;
private readonly CompatibilitySwitch<bool> _enableGlobalRouting;
private readonly CompatibilitySwitch<bool> _enableEndpointRouting;
private readonly ICompatibilitySwitch[] _switches;
/// <summary>
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Mvc
_allowValidatingTopLevelNodes = new CompatibilitySwitch<bool>(nameof(AllowValidatingTopLevelNodes));
_inputFormatterExceptionPolicy = new CompatibilitySwitch<InputFormatterExceptionPolicy>(nameof(InputFormatterExceptionPolicy), InputFormatterExceptionPolicy.AllExceptions);
_suppressBindingUndefinedValueToEnumType = new CompatibilitySwitch<bool>(nameof(SuppressBindingUndefinedValueToEnumType));
_enableGlobalRouting = new CompatibilitySwitch<bool>(nameof(EnableGlobalRouting));
_enableEndpointRouting = new CompatibilitySwitch<bool>(nameof(EnableEndpointRouting));
_switches = new ICompatibilitySwitch[]
{
@ -64,15 +64,22 @@ namespace Microsoft.AspNetCore.Mvc
_allowValidatingTopLevelNodes,
_inputFormatterExceptionPolicy,
_suppressBindingUndefinedValueToEnumType,
_enableGlobalRouting,
_enableEndpointRouting,
};
}
// REVIEW: Add documentation
// REVIEW: Remove once web hooks is using EnableEndpointRouting
public bool EnableGlobalRouting
{
get => _enableGlobalRouting.Value;
set => _enableGlobalRouting.Value = value;
get => EnableEndpointRouting;
set => EnableEndpointRouting = value;
}
// REVIEW: Add documentation
public bool EnableEndpointRouting
{
get => _enableEndpointRouting.Value;
set => _enableEndpointRouting.Value = value;
}
/// <summary>

View File

@ -12,14 +12,14 @@ namespace Microsoft.AspNetCore.Mvc.Routing
/// An implementation of <see cref="IUrlHelper"/> that uses <see cref="LinkGenerator"/> to build URLs
/// for ASP.NET MVC within an application.
/// </summary>
internal class GlobalRoutingUrlHelper : UrlHelperBase
internal class EndpointRoutingUrlHelper : UrlHelperBase
{
private readonly ILogger<GlobalRoutingUrlHelper> _logger;
private readonly ILogger<EndpointRoutingUrlHelper> _logger;
private readonly LinkGenerator _linkGenerator;
private readonly IEndpointFinder<RouteValuesBasedEndpointFinderContext> _routeValuesBasedEndpointFinder;
/// <summary>
/// Initializes a new instance of the <see cref="GlobalRoutingUrlHelper"/> class using the specified
/// Initializes a new instance of the <see cref="EndpointRoutingUrlHelper"/> class using the specified
/// <paramref name="actionContext"/>.
/// </summary>
/// <param name="actionContext">The <see cref="Mvc.ActionContext"/> for the current request.</param>
@ -28,11 +28,11 @@ namespace Microsoft.AspNetCore.Mvc.Routing
/// </param>
/// <param name="linkGenerator">The <see cref="LinkGenerator"/> used to generate the link.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param>
public GlobalRoutingUrlHelper(
public EndpointRoutingUrlHelper(
ActionContext actionContext,
IEndpointFinder<RouteValuesBasedEndpointFinderContext> routeValuesBasedEndpointFinder,
LinkGenerator linkGenerator,
ILogger<GlobalRoutingUrlHelper> logger)
ILogger<EndpointRoutingUrlHelper> logger)
: base(actionContext)
{
if (linkGenerator == null)

View File

@ -53,9 +53,9 @@ namespace Microsoft.AspNetCore.Mvc.Routing
var services = httpContext.RequestServices;
var linkGenerator = services.GetRequiredService<LinkGenerator>();
var routeValuesBasedEndpointFinder = services.GetRequiredService<IEndpointFinder<RouteValuesBasedEndpointFinderContext>>();
var logger = services.GetRequiredService<ILogger<GlobalRoutingUrlHelper>>();
var logger = services.GetRequiredService<ILogger<EndpointRoutingUrlHelper>>();
urlHelper = new GlobalRoutingUrlHelper(
urlHelper = new EndpointRoutingUrlHelper(
context,
routeValuesBasedEndpointFinder,
linkGenerator,

View File

@ -58,13 +58,13 @@ namespace Microsoft.AspNetCore.Mvc.Core.Builder
}
[Fact]
public void UseMvc_GlobalRoutingDisabled_NoEndpointInfos()
public void UseMvc_EndpointRoutingDisabled_NoEndpointInfos()
{
// Arrange
var services = new ServiceCollection();
services.AddSingleton<DiagnosticSource>(new DiagnosticListener("Microsoft.AspNetCore"));
services.AddLogging();
services.AddMvcCore(o => o.EnableGlobalRouting = false);
services.AddMvcCore(o => o.EnableEndpointRouting = false);
var serviceProvider = services.BuildServiceProvider();
var appBuilder = new ApplicationBuilder(serviceProvider);
@ -85,13 +85,13 @@ namespace Microsoft.AspNetCore.Mvc.Core.Builder
}
[Fact]
public void UseMvc_GlobalRoutingEnabled_NoEndpointInfos()
public void UseMvc_EndpointRoutingEnabled_NoEndpointInfos()
{
// Arrange
var services = new ServiceCollection();
services.AddSingleton<DiagnosticSource>(new DiagnosticListener("Microsoft.AspNetCore"));
services.AddLogging();
services.AddMvcCore(o => o.EnableGlobalRouting = true);
services.AddMvcCore(o => o.EnableEndpointRouting = true);
var serviceProvider = services.BuildServiceProvider();
var appBuilder = new ApplicationBuilder(serviceProvider);

View File

@ -14,7 +14,7 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.Routing
{
public class GlobalRoutingUrlHelperTest : UrlHelperTestBase
public class EndpointRoutingUrlHelperTest : UrlHelperTestBase
{
[Fact]
public void RouteUrl_WithRouteName_GeneratesUrl_UsingDefaults()
@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
var urlHelperFactory = httpContext.RequestServices.GetRequiredService<IUrlHelperFactory>();
var urlHelper = urlHelperFactory.GetUrlHelper(actionContext);
Assert.IsType<GlobalRoutingUrlHelper>(urlHelper);
Assert.IsType<EndpointRoutingUrlHelper>(urlHelper);
return urlHelper;
}

View File

@ -8,9 +8,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{
public class ConsumesAttributeGlobalRoutingTests : ConsumesAttributeTestsBase<BasicWebSite.StartupWithGlobalRouting>
public class ConsumesAttributeEndpointRoutingTests : ConsumesAttributeTestsBase<BasicWebSite.StartupWithEndpointRouting>
{
public ConsumesAttributeGlobalRoutingTests(MvcTestFixture<BasicWebSite.StartupWithGlobalRouting> fixture)
public ConsumesAttributeEndpointRoutingTests(MvcTestFixture<BasicWebSite.StartupWithEndpointRouting> fixture)
: base(fixture)
{
}

View File

@ -9,9 +9,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{
public class CorsGlobalRoutingTests : CorsTestsBase<CorsWebSite.StartupWithGlobalRouting>
public class CorsEndpointRoutingTests : CorsTestsBase<CorsWebSite.StartupWithEndpointRouting>
{
public CorsGlobalRoutingTests(MvcTestFixture<CorsWebSite.StartupWithGlobalRouting> fixture)
public CorsEndpointRoutingTests(MvcTestFixture<CorsWebSite.StartupWithEndpointRouting> fixture)
: base(fixture)
{
}

View File

@ -10,9 +10,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{
public class GlobalRoutingTest : RoutingTestsBase<RoutingWebSite.StartupWithGlobalRouting>
public class EndpointRoutingTest : RoutingTestsBase<RoutingWebSite.StartupWithEndpointRouting>
{
public GlobalRoutingTest(MvcTestFixture<RoutingWebSite.StartupWithGlobalRouting> fixture)
public EndpointRoutingTest(MvcTestFixture<RoutingWebSite.StartupWithEndpointRouting> fixture)
: base(fixture)
{
}

View File

@ -8,9 +8,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{
public class RequestServicesGlobalRoutingTest : RequestServicesTestBase<BasicWebSite.StartupWithGlobalRouting>
public class RequestServicesEndpointRoutingTest : RequestServicesTestBase<BasicWebSite.StartupWithEndpointRouting>
{
public RequestServicesGlobalRoutingTest(MvcTestFixture<BasicWebSite.StartupWithGlobalRouting> fixture)
public RequestServicesEndpointRoutingTest(MvcTestFixture<BasicWebSite.StartupWithEndpointRouting> fixture)
: base(fixture)
{
}

View File

@ -9,9 +9,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{
public class VersioningGlobalRoutingTests : VersioningTestsBase<VersioningWebSite.StartupWithGlobalRouting>
public class VersioningEndpointRoutingTests : VersioningTestsBase<VersioningWebSite.StartupWithEndpointRouting>
{
public VersioningGlobalRoutingTests(MvcTestFixture<VersioningWebSite.StartupWithGlobalRouting> fixture)
public VersioningEndpointRoutingTests(MvcTestFixture<VersioningWebSite.StartupWithEndpointRouting> fixture)
: base(fixture)
{
}

View File

@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
Assert.Equal(InputFormatterExceptionPolicy.AllExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.False(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.False(razorPagesOptions.AllowAreas);
Assert.False(mvcOptions.EnableGlobalRouting);
Assert.False(mvcOptions.EnableEndpointRouting);
}
[Fact]
@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.True(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.True(razorPagesOptions.AllowAreas);
Assert.False(mvcOptions.EnableGlobalRouting);
Assert.False(mvcOptions.EnableEndpointRouting);
}
[Fact]
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.True(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.True(razorPagesOptions.AllowAreas);
Assert.True(mvcOptions.EnableGlobalRouting);
Assert.True(mvcOptions.EnableEndpointRouting);
}
[Fact]
@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.True(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.True(razorPagesOptions.AllowAreas);
Assert.True(mvcOptions.EnableGlobalRouting);
Assert.True(mvcOptions.EnableEndpointRouting);
}
// This just does the minimum needed to be able to resolve these options.

View File

@ -28,7 +28,7 @@ namespace BasicWebSite
options.Filters.Add(new TraceResourceFilter());
// Remove when all URL generation tests are passing - https://github.com/aspnet/Routing/issues/590
options.EnableGlobalRouting = false;
options.EnableEndpointRouting = false;
})
.SetCompatibilityVersion(CompatibilityVersion.Latest)
.AddXmlDataContractSerializerFormatters();

View File

@ -7,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection;
namespace BasicWebSite
{
public class StartupWithGlobalRouting
public class StartupWithEndpointRouting
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
@ -29,8 +29,6 @@ namespace BasicWebSite
// Initializes the RequestId service for each request
app.UseMiddleware<RequestIdMiddleware>();
app.UseGlobalRouting();
app.UseMvc(routes =>
{
routes.MapRoute(

View File

@ -9,11 +9,11 @@ using Microsoft.Extensions.DependencyInjection;
namespace CorsWebSite
{
public class StartupWithGlobalRouting
public class StartupWithEndpointRouting
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options => options.EnableGlobalRouting = true);
services.AddMvc(options => options.EnableEndpointRouting = true);
services.Configure<CorsOptions>(options =>
{
options.AddPolicy(

View File

@ -7,13 +7,13 @@ using Microsoft.Extensions.DependencyInjection;
namespace RoutingWebSite
{
public class StartupWithGlobalRouting
public class StartupWithEndpointRouting
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddMvcOptions(options => options.EnableGlobalRouting = true);
.AddMvcOptions(options => options.EnableEndpointRouting = true);
services.AddScoped<TestResponseGenerator>();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();

View File

@ -9,13 +9,13 @@ using Microsoft.Extensions.DependencyInjection;
namespace VersioningWebSite
{
public class StartupWithGlobalRouting
public class StartupWithEndpointRouting
{
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container
services.AddMvc()
.AddMvcOptions(options => options.EnableGlobalRouting = true);
.AddMvcOptions(options => options.EnableEndpointRouting = true);
services.AddScoped<TestResponseGenerator>();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();