Merge remote-tracking branch 'origin/release/2.2'
This commit is contained in:
commit
3c1034cf12
|
|
@ -261,7 +261,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
services.TryAddTransient<MvcAttributeRouteHandler>(); // Many per app
|
||||
|
||||
//
|
||||
// Dispatching
|
||||
// Global Routing / Endpoints
|
||||
//
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<EndpointDataSource, MvcEndpointDataSource>());
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
// up the endpoints too.
|
||||
//
|
||||
// Start with an order of '1' for conventional routes as attribute routes have a default order of '0'.
|
||||
// This is for scenarios dealing with migrating existing Routing based code to Dispatcher world.
|
||||
// This is for scenarios dealing with migrating existing Router based code to Global Routing world.
|
||||
var conventionalRouteOrder = 0;
|
||||
|
||||
// Check each of the conventional templates to see if the action would be reachable
|
||||
|
|
|
|||
|
|
@ -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 DispatcherUrlHelper : UrlHelperBase
|
||||
internal class GlobalRoutingUrlHelper : UrlHelperBase
|
||||
{
|
||||
private readonly ILogger<DispatcherUrlHelper> _logger;
|
||||
private readonly ILogger<GlobalRoutingUrlHelper> _logger;
|
||||
private readonly LinkGenerator _linkGenerator;
|
||||
private readonly IEndpointFinder<RouteValuesBasedEndpointFinderContext> _routeValuesBasedEndpointFinder;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DispatcherUrlHelper"/> class using the specified
|
||||
/// Initializes a new instance of the <see cref="GlobalRoutingUrlHelper"/> 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 DispatcherUrlHelper(
|
||||
public GlobalRoutingUrlHelper(
|
||||
ActionContext actionContext,
|
||||
IEndpointFinder<RouteValuesBasedEndpointFinderContext> routeValuesBasedEndpointFinder,
|
||||
LinkGenerator linkGenerator,
|
||||
ILogger<DispatcherUrlHelper> logger)
|
||||
ILogger<GlobalRoutingUrlHelper> logger)
|
||||
: base(actionContext)
|
||||
{
|
||||
if (linkGenerator == null)
|
||||
|
|
@ -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<DispatcherUrlHelper>>();
|
||||
var logger = services.GetRequiredService<ILogger<GlobalRoutingUrlHelper>>();
|
||||
|
||||
urlHelper = new DispatcherUrlHelper(
|
||||
urlHelper = new GlobalRoutingUrlHelper(
|
||||
context,
|
||||
routeValuesBasedEndpointFinder,
|
||||
linkGenerator,
|
||||
|
|
|
|||
|
|
@ -71,11 +71,24 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
};
|
||||
}
|
||||
|
||||
string message = null;
|
||||
if (!output.IsContentModified)
|
||||
{
|
||||
var tagHelperContent = await output.GetChildContentAsync();
|
||||
|
||||
// We check for whitespace to detect scenarios such as:
|
||||
// <span validation-for="Name">
|
||||
// </span>
|
||||
if (!tagHelperContent.IsEmptyOrWhiteSpace)
|
||||
{
|
||||
message = tagHelperContent.GetContent();
|
||||
}
|
||||
}
|
||||
var tagBuilder = Generator.GenerateValidationMessage(
|
||||
ViewContext,
|
||||
For.ModelExplorer,
|
||||
For.Name,
|
||||
message: null,
|
||||
message: message,
|
||||
tag: null,
|
||||
htmlAttributes: htmlAttributes);
|
||||
|
||||
|
|
@ -84,27 +97,12 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
output.MergeAttributes(tagBuilder);
|
||||
|
||||
// Do not update the content if another tag helper targeting this element has already done so.
|
||||
if (!output.IsContentModified)
|
||||
if (!output.IsContentModified && tagBuilder.HasInnerHtml)
|
||||
{
|
||||
// We check for whitespace to detect scenarios such as:
|
||||
// <span validation-for="Name">
|
||||
// </span>
|
||||
var childContent = await output.GetChildContentAsync();
|
||||
if (childContent.IsEmptyOrWhiteSpace)
|
||||
{
|
||||
// Provide default message text (if any) since there was nothing useful in the Razor source.
|
||||
if (tagBuilder.HasInnerHtml)
|
||||
{
|
||||
output.Content.SetHtmlContent(tagBuilder.InnerHtml);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Content.SetHtmlContent(childContent);
|
||||
}
|
||||
output.Content.SetHtmlContent(tagBuilder.InnerHtml);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ using Xunit;
|
|||
|
||||
namespace Microsoft.AspNetCore.Mvc.Routing
|
||||
{
|
||||
public class DispatcherUrlHelperTest : UrlHelperTestBase
|
||||
public class GlobalRoutingUrlHelperTest : UrlHelperTestBase
|
||||
{
|
||||
protected override IUrlHelper CreateUrlHelper(string appRoot, string host, string protocol)
|
||||
{
|
||||
|
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
|||
|
||||
var urlHelperFactory = httpContext.RequestServices.GetRequiredService<IUrlHelperFactory>();
|
||||
var urlHelper = urlHelperFactory.GetUrlHelper(actionContext);
|
||||
Assert.IsType<DispatcherUrlHelper>(urlHelper);
|
||||
Assert.IsType<GlobalRoutingUrlHelper>(urlHelper);
|
||||
return urlHelper;
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
|||
}
|
||||
|
||||
var services = GetCommonServices();
|
||||
services.AddDispatcher();
|
||||
services.AddRouting();
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<EndpointDataSource>(new DefaultEndpointDataSource(endpoints)));
|
||||
services.TryAddSingleton<IUrlHelperFactory, UrlHelperFactory>();
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||
{
|
||||
public class ConsumesAttributeDispatchingTests : ConsumesAttributeTestsBase<BasicWebSite.StartupWithDispatching>
|
||||
public class ConsumesAttributeGlobalRoutingTests : ConsumesAttributeTestsBase<BasicWebSite.StartupWithGlobalRouting>
|
||||
{
|
||||
public ConsumesAttributeDispatchingTests(MvcTestFixture<BasicWebSite.StartupWithDispatching> fixture)
|
||||
public ConsumesAttributeGlobalRoutingTests(MvcTestFixture<BasicWebSite.StartupWithGlobalRouting> fixture)
|
||||
: base(fixture)
|
||||
{
|
||||
}
|
||||
|
|
@ -4,39 +4,25 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||
{
|
||||
public class DispatchingTests : RoutingTestsBase<RoutingWebSite.StartupWithDispatching>
|
||||
public class GlobalRoutingTest : RoutingTestsBase<RoutingWebSite.StartupWithGlobalRouting>
|
||||
{
|
||||
public DispatchingTests(MvcTestFixture<RoutingWebSite.StartupWithDispatching> fixture)
|
||||
public GlobalRoutingTest(MvcTestFixture<RoutingWebSite.StartupWithGlobalRouting> fixture)
|
||||
: base(fixture)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact(Skip = "Link generation issue in dispatching. Need to fix - https://github.com/aspnet/Routing/issues/590")]
|
||||
public override Task AttributeRoutedAction_InArea_ExplicitLeaveArea()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Fact(Skip = "Link generation issue in dispatching. Need to fix - https://github.com/aspnet/Routing/issues/590")]
|
||||
[Fact(Skip = "Link generation issue in global routing. Need to fix - https://github.com/aspnet/Routing/issues/590")]
|
||||
public override Task AttributeRoutedAction_InArea_StaysInArea_ActionDoesntExist()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Fact(Skip = "Link generation issue in dispatching. Need to fix - https://github.com/aspnet/Routing/issues/590")]
|
||||
public override Task ConventionalRoutedAction_InArea_ExplicitLeaveArea()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Fact(Skip = "Link generation issue in dispatching. Need to fix - https://github.com/aspnet/Routing/issues/590")]
|
||||
[Fact(Skip = "Link generation issue in global routing. Need to fix - https://github.com/aspnet/Routing/issues/590")]
|
||||
public override Task ConventionalRoutedAction_InArea_StaysInArea()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||
{
|
||||
public class VersioningDispatchingTests : VersioningTestsBase<VersioningWebSite.StartupWithDispatching>
|
||||
public class RequestServicesGlobalRoutingTest : RequestServicesTestBase<BasicWebSite.StartupWithGlobalRouting>
|
||||
{
|
||||
public VersioningDispatchingTests(MvcTestFixture<VersioningWebSite.StartupWithDispatching> fixture)
|
||||
public RequestServicesGlobalRoutingTest(MvcTestFixture<BasicWebSite.StartupWithGlobalRouting> fixture)
|
||||
: base(fixture)
|
||||
{
|
||||
}
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||
{
|
||||
public class RequestServicesDispatchingTest : RequestServicesTestBase<BasicWebSite.StartupWithDispatching>
|
||||
public class VersioningGlobalRoutingTests : VersioningTestsBase<VersioningWebSite.StartupWithGlobalRouting>
|
||||
{
|
||||
public RequestServicesDispatchingTest(MvcTestFixture<BasicWebSite.StartupWithDispatching> fixture)
|
||||
public VersioningGlobalRoutingTests(MvcTestFixture<VersioningWebSite.StartupWithGlobalRouting> fixture)
|
||||
: base(fixture)
|
||||
{
|
||||
}
|
||||
|
|
@ -357,10 +357,11 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Content of validation message", "Content of validation message")]
|
||||
[InlineData("\r\n \r\n", "New HTML")]
|
||||
[InlineData("Content of validation message", "Content of validation message", "New HTML")]
|
||||
[InlineData("\r\n \r\n", null, "New HTML")]
|
||||
public async Task ProcessAsync_MergesTagBuilderFromGenerateValidationMessage(
|
||||
string childContent,
|
||||
string expectedMessage,
|
||||
string expectedOutputContent)
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -375,7 +376,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
It.IsAny<ViewContext>(),
|
||||
It.IsAny<ModelExplorer>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<string>(),
|
||||
expectedMessage,
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<object>()))
|
||||
.Returns(tagBuilder);
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
|
||||
namespace BasicWebSite
|
||||
{
|
||||
public class StartupWithDispatching
|
||||
public class StartupWithGlobalRouting
|
||||
{
|
||||
// Set up application services
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDispatcher();
|
||||
services.AddRouting();
|
||||
|
||||
services.AddMvc()
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Latest)
|
||||
|
|
@ -29,7 +29,7 @@ namespace BasicWebSite
|
|||
// Initializes the RequestId service for each request
|
||||
app.UseMiddleware<RequestIdMiddleware>();
|
||||
|
||||
app.UseDispatcher();
|
||||
app.UseGlobalRouting();
|
||||
|
||||
app.UseMvcWithEndpoint(routes =>
|
||||
{
|
||||
|
|
@ -1,27 +1,18 @@
|
|||
// 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;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Routing.Matchers;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace RoutingWebSite
|
||||
{
|
||||
public class StartupWithDispatching
|
||||
public class StartupWithGlobalRouting
|
||||
{
|
||||
// Set up application services
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDispatcher();
|
||||
services.AddRouting();
|
||||
|
||||
services.AddMvc();
|
||||
|
||||
|
|
@ -31,7 +22,7 @@ namespace RoutingWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseDispatcher();
|
||||
app.UseGlobalRouting();
|
||||
|
||||
app.UseMvcWithEndpoint(routes =>
|
||||
{
|
||||
|
|
@ -9,11 +9,11 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
|
||||
namespace VersioningWebSite
|
||||
{
|
||||
public class StartupWithDispatching
|
||||
public class StartupWithGlobalRouting
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDispatcher();
|
||||
services.AddRouting();
|
||||
|
||||
// Add MVC services to the services container
|
||||
services.AddMvc();
|
||||
|
|
@ -24,7 +24,7 @@ namespace VersioningWebSite
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseDispatcher();
|
||||
app.UseGlobalRouting();
|
||||
|
||||
app.UseMvcWithEndpoint(endpoints =>
|
||||
{
|
||||
Loading…
Reference in New Issue