Merge branch 'merge/release/2.2-to-master'

This commit is contained in:
James Newton-King 2018-08-01 16:00:19 +12:00
commit c902e5d312
No known key found for this signature in database
GPG Key ID: 0A66B2F456BF5526
18 changed files with 53 additions and 48 deletions

View File

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

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc
private readonly CompatibilitySwitch<bool> _allowValidatingTopLevelNodes; private readonly CompatibilitySwitch<bool> _allowValidatingTopLevelNodes;
private readonly CompatibilitySwitch<InputFormatterExceptionPolicy> _inputFormatterExceptionPolicy; private readonly CompatibilitySwitch<InputFormatterExceptionPolicy> _inputFormatterExceptionPolicy;
private readonly CompatibilitySwitch<bool> _suppressBindingUndefinedValueToEnumType; private readonly CompatibilitySwitch<bool> _suppressBindingUndefinedValueToEnumType;
private readonly CompatibilitySwitch<bool> _enableGlobalRouting; private readonly CompatibilitySwitch<bool> _enableEndpointRouting;
private readonly ICompatibilitySwitch[] _switches; private readonly ICompatibilitySwitch[] _switches;
/// <summary> /// <summary>
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Mvc
_allowValidatingTopLevelNodes = new CompatibilitySwitch<bool>(nameof(AllowValidatingTopLevelNodes)); _allowValidatingTopLevelNodes = new CompatibilitySwitch<bool>(nameof(AllowValidatingTopLevelNodes));
_inputFormatterExceptionPolicy = new CompatibilitySwitch<InputFormatterExceptionPolicy>(nameof(InputFormatterExceptionPolicy), InputFormatterExceptionPolicy.AllExceptions); _inputFormatterExceptionPolicy = new CompatibilitySwitch<InputFormatterExceptionPolicy>(nameof(InputFormatterExceptionPolicy), InputFormatterExceptionPolicy.AllExceptions);
_suppressBindingUndefinedValueToEnumType = new CompatibilitySwitch<bool>(nameof(SuppressBindingUndefinedValueToEnumType)); _suppressBindingUndefinedValueToEnumType = new CompatibilitySwitch<bool>(nameof(SuppressBindingUndefinedValueToEnumType));
_enableGlobalRouting = new CompatibilitySwitch<bool>(nameof(EnableGlobalRouting)); _enableEndpointRouting = new CompatibilitySwitch<bool>(nameof(EnableEndpointRouting));
_switches = new ICompatibilitySwitch[] _switches = new ICompatibilitySwitch[]
{ {
@ -64,15 +64,22 @@ namespace Microsoft.AspNetCore.Mvc
_allowValidatingTopLevelNodes, _allowValidatingTopLevelNodes,
_inputFormatterExceptionPolicy, _inputFormatterExceptionPolicy,
_suppressBindingUndefinedValueToEnumType, _suppressBindingUndefinedValueToEnumType,
_enableGlobalRouting, _enableEndpointRouting,
}; };
} }
// REVIEW: Add documentation // REVIEW: Remove once web hooks is using EnableEndpointRouting
public bool EnableGlobalRouting public bool EnableGlobalRouting
{ {
get => _enableGlobalRouting.Value; get => EnableEndpointRouting;
set => _enableGlobalRouting.Value = value; set => EnableEndpointRouting = value;
}
// REVIEW: Add documentation
public bool EnableEndpointRouting
{
get => _enableEndpointRouting.Value;
set => _enableEndpointRouting.Value = value;
} }
/// <summary> /// <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 /// An implementation of <see cref="IUrlHelper"/> that uses <see cref="LinkGenerator"/> to build URLs
/// for ASP.NET MVC within an application. /// for ASP.NET MVC within an application.
/// </summary> /// </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 LinkGenerator _linkGenerator;
private readonly IEndpointFinder<RouteValuesBasedEndpointFinderContext> _routeValuesBasedEndpointFinder; private readonly IEndpointFinder<RouteValuesBasedEndpointFinderContext> _routeValuesBasedEndpointFinder;
/// <summary> /// <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"/>. /// <paramref name="actionContext"/>.
/// </summary> /// </summary>
/// <param name="actionContext">The <see cref="Mvc.ActionContext"/> for the current request.</param> /// <param name="actionContext">The <see cref="Mvc.ActionContext"/> for the current request.</param>
@ -28,11 +28,11 @@ namespace Microsoft.AspNetCore.Mvc.Routing
/// </param> /// </param>
/// <param name="linkGenerator">The <see cref="LinkGenerator"/> used to generate the link.</param> /// <param name="linkGenerator">The <see cref="LinkGenerator"/> used to generate the link.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param> /// <param name="logger">The <see cref="ILogger"/>.</param>
public GlobalRoutingUrlHelper( public EndpointRoutingUrlHelper(
ActionContext actionContext, ActionContext actionContext,
IEndpointFinder<RouteValuesBasedEndpointFinderContext> routeValuesBasedEndpointFinder, IEndpointFinder<RouteValuesBasedEndpointFinderContext> routeValuesBasedEndpointFinder,
LinkGenerator linkGenerator, LinkGenerator linkGenerator,
ILogger<GlobalRoutingUrlHelper> logger) ILogger<EndpointRoutingUrlHelper> logger)
: base(actionContext) : base(actionContext)
{ {
if (linkGenerator == null) if (linkGenerator == null)

View File

@ -53,9 +53,9 @@ namespace Microsoft.AspNetCore.Mvc.Routing
var services = httpContext.RequestServices; var services = httpContext.RequestServices;
var linkGenerator = services.GetRequiredService<LinkGenerator>(); var linkGenerator = services.GetRequiredService<LinkGenerator>();
var routeValuesBasedEndpointFinder = services.GetRequiredService<IEndpointFinder<RouteValuesBasedEndpointFinderContext>>(); 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, context,
routeValuesBasedEndpointFinder, routeValuesBasedEndpointFinder,
linkGenerator, linkGenerator,

View File

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

View File

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

View File

@ -8,9 +8,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests 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) : base(fixture)
{ {
} }

View File

@ -9,9 +9,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests 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) : base(fixture)
{ {
} }

View File

@ -10,9 +10,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests 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) : base(fixture)
{ {
} }

View File

@ -8,9 +8,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests 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) : base(fixture)
{ {
} }

View File

@ -9,9 +9,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests 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) : base(fixture)
{ {
} }

View File

@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
Assert.Equal(InputFormatterExceptionPolicy.AllExceptions, mvcOptions.InputFormatterExceptionPolicy); Assert.Equal(InputFormatterExceptionPolicy.AllExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.False(jsonOptions.AllowInputFormatterExceptionMessages); Assert.False(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.False(razorPagesOptions.AllowAreas); Assert.False(razorPagesOptions.AllowAreas);
Assert.False(mvcOptions.EnableGlobalRouting); Assert.False(mvcOptions.EnableEndpointRouting);
} }
[Fact] [Fact]
@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy); Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.True(jsonOptions.AllowInputFormatterExceptionMessages); Assert.True(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.True(razorPagesOptions.AllowAreas); Assert.True(razorPagesOptions.AllowAreas);
Assert.False(mvcOptions.EnableGlobalRouting); Assert.False(mvcOptions.EnableEndpointRouting);
} }
[Fact] [Fact]
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy); Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.True(jsonOptions.AllowInputFormatterExceptionMessages); Assert.True(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.True(razorPagesOptions.AllowAreas); Assert.True(razorPagesOptions.AllowAreas);
Assert.True(mvcOptions.EnableGlobalRouting); Assert.True(mvcOptions.EnableEndpointRouting);
} }
[Fact] [Fact]
@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy); Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.True(jsonOptions.AllowInputFormatterExceptionMessages); Assert.True(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.True(razorPagesOptions.AllowAreas); 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. // 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()); options.Filters.Add(new TraceResourceFilter());
// Remove when all URL generation tests are passing - https://github.com/aspnet/Routing/issues/590 // Remove when all URL generation tests are passing - https://github.com/aspnet/Routing/issues/590
options.EnableGlobalRouting = false; options.EnableEndpointRouting = false;
}) })
.SetCompatibilityVersion(CompatibilityVersion.Latest) .SetCompatibilityVersion(CompatibilityVersion.Latest)
.AddXmlDataContractSerializerFormatters(); .AddXmlDataContractSerializerFormatters();

View File

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

View File

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

View File

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

View File

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