Design extensibility for executors
We have all of these executors but they aren't really documented/supported for extensibility today. This change introduces a pattern for action result executors so we can make them extensible.
This commit is contained in:
parent
5d1603c37f
commit
38712609bb
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
|
@ -32,7 +33,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<ContentResultExecutor>();
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<ContentResult>>();
|
||||||
return executor.ExecuteAsync(context, this);
|
return executor.ExecuteAsync(context, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -250,17 +250,17 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
services.TryAddSingleton<IHttpResponseStreamWriterFactory, MemoryPoolHttpResponseStreamWriterFactory>();
|
services.TryAddSingleton<IHttpResponseStreamWriterFactory, MemoryPoolHttpResponseStreamWriterFactory>();
|
||||||
services.TryAddSingleton(ArrayPool<byte>.Shared);
|
services.TryAddSingleton(ArrayPool<byte>.Shared);
|
||||||
services.TryAddSingleton(ArrayPool<char>.Shared);
|
services.TryAddSingleton(ArrayPool<char>.Shared);
|
||||||
services.TryAddSingleton<ObjectResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<ObjectResult>, ObjectResultExecutor>();
|
||||||
services.TryAddSingleton<PhysicalFileResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<PhysicalFileResult>, PhysicalFileResultExecutor>();
|
||||||
services.TryAddSingleton<VirtualFileResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<VirtualFileResult>, VirtualFileResultExecutor>();
|
||||||
services.TryAddSingleton<FileStreamResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<FileStreamResult>, FileStreamResultExecutor>();
|
||||||
services.TryAddSingleton<FileContentResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<FileContentResult>, FileContentResultExecutor>();
|
||||||
services.TryAddSingleton<RedirectResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<RedirectResult>, RedirectResultExecutor>();
|
||||||
services.TryAddSingleton<LocalRedirectResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<LocalRedirectResult>, LocalRedirectResultExecutor>();
|
||||||
services.TryAddSingleton<RedirectToActionResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<RedirectToActionResult>, RedirectToActionResultExecutor>();
|
||||||
services.TryAddSingleton<RedirectToRouteResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<RedirectToRouteResult>, RedirectToRouteResultExecutor>();
|
||||||
services.TryAddSingleton<RedirectToPageResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<RedirectToPageResult>, RedirectToPageResultExecutor>();
|
||||||
services.TryAddSingleton<ContentResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<ContentResult>, ContentResultExecutor>();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Route Handlers
|
// Route Handlers
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
@ -76,7 +77,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<FileContentResultExecutor>();
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<FileContentResult>>();
|
||||||
return executor.ExecuteAsync(context, this);
|
return executor.ExecuteAsync(context, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
@ -73,7 +74,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<FileStreamResultExecutor>();
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<FileStreamResult>>();
|
||||||
return executor.ExecuteAsync(context, this);
|
return executor.ExecuteAsync(context, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class ContentResultExecutor
|
public class ContentResultExecutor : IActionResultExecutor<ContentResult>
|
||||||
{
|
{
|
||||||
private const string DefaultContentType = "text/plain; charset=utf-8";
|
private const string DefaultContentType = "text/plain; charset=utf-8";
|
||||||
private readonly ILogger<ContentResultExecutor> _logger;
|
private readonly ILogger<ContentResultExecutor> _logger;
|
||||||
|
|
@ -20,6 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
_httpResponseStreamWriterFactory = httpResponseStreamWriterFactory;
|
_httpResponseStreamWriterFactory = httpResponseStreamWriterFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public virtual async Task ExecuteAsync(ActionContext context, ContentResult result)
|
public virtual async Task ExecuteAsync(ActionContext context, ContentResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -7,15 +7,16 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class FileContentResultExecutor : FileResultExecutorBase
|
public class FileContentResultExecutor : FileResultExecutorBase, IActionResultExecutor<FileContentResult>
|
||||||
{
|
{
|
||||||
public FileContentResultExecutor(ILoggerFactory loggerFactory)
|
public FileContentResultExecutor(ILoggerFactory loggerFactory)
|
||||||
: base(CreateLogger<FileContentResultExecutor>(loggerFactory))
|
: base(CreateLogger<FileContentResultExecutor>(loggerFactory))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public virtual Task ExecuteAsync(ActionContext context, FileContentResult result)
|
public virtual Task ExecuteAsync(ActionContext context, FileContentResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -10,10 +10,11 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Extensions;
|
using Microsoft.AspNetCore.Http.Extensions;
|
||||||
using Microsoft.AspNetCore.Http.Headers;
|
using Microsoft.AspNetCore.Http.Headers;
|
||||||
using Microsoft.AspNetCore.Internal;
|
using Microsoft.AspNetCore.Internal;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class FileResultExecutorBase
|
public class FileResultExecutorBase
|
||||||
{
|
{
|
||||||
|
|
@ -6,15 +6,16 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class FileStreamResultExecutor : FileResultExecutorBase
|
public class FileStreamResultExecutor : FileResultExecutorBase, IActionResultExecutor<FileStreamResult>
|
||||||
{
|
{
|
||||||
public FileStreamResultExecutor(ILoggerFactory loggerFactory)
|
public FileStreamResultExecutor(ILoggerFactory loggerFactory)
|
||||||
: base(CreateLogger<FileStreamResultExecutor>(loggerFactory))
|
: base(CreateLogger<FileStreamResultExecutor>(loggerFactory))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public virtual Task ExecuteAsync(ActionContext context, FileStreamResult result)
|
public virtual Task ExecuteAsync(ActionContext context, FileStreamResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
// 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.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Defines an interface for a service which can execute a particular kind of <see cref="IActionResult"/> by
|
||||||
|
/// manipulating the <see cref="HttpResponse"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TResult">The type of <see cref="IActionResult"/>.</typeparam>
|
||||||
|
/// <remarks>
|
||||||
|
/// Implementions of <see cref="IActionResultExecutor{TResult}"/> are typically called by the
|
||||||
|
/// <see cref="IActionResult.ExecuteResultAsync(ActionContext)"/> method of the corresponding action result type.
|
||||||
|
/// Implementations should be registered as singleton services.
|
||||||
|
/// </remarks>
|
||||||
|
public interface IActionResultExecutor<in TResult> where TResult : IActionResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Asynchronously excecutes the action result, by modifying the <see cref="HttpResponse"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">The <see cref="ActionContext"/> associated with the current request."/></param>
|
||||||
|
/// <param name="result">The action result to execute.</param>
|
||||||
|
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
|
||||||
|
Task ExecuteAsync(ActionContext context, TResult result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,15 +2,17 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Core;
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class LocalRedirectResultExecutor
|
public class LocalRedirectResultExecutor : IActionResultExecutor<LocalRedirectResult>
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IUrlHelperFactory _urlHelperFactory;
|
private readonly IUrlHelperFactory _urlHelperFactory;
|
||||||
|
|
@ -31,7 +33,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
_urlHelperFactory = urlHelperFactory;
|
_urlHelperFactory = urlHelperFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Execute(ActionContext context, LocalRedirectResult result)
|
/// <inheritdoc />
|
||||||
|
public virtual Task ExecuteAsync(ActionContext context, LocalRedirectResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
|
|
@ -64,6 +67,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
{
|
{
|
||||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,17 +11,18 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Core;
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters.Internal;
|
using Microsoft.AspNetCore.Mvc.Formatters.Internal;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes an <see cref="ObjectResult"/> to write to the response.
|
/// Executes an <see cref="ObjectResult"/> to write to the response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ObjectResultExecutor
|
public class ObjectResultExecutor : IActionResultExecutor<ObjectResult>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="ObjectResultExecutor"/>.
|
/// Creates a new <see cref="ObjectResultExecutor"/>.
|
||||||
|
|
@ -10,15 +10,16 @@ using Microsoft.AspNetCore.Mvc.Core;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class PhysicalFileResultExecutor : FileResultExecutorBase
|
public class PhysicalFileResultExecutor : FileResultExecutorBase, IActionResultExecutor<PhysicalFileResult>
|
||||||
{
|
{
|
||||||
public PhysicalFileResultExecutor(ILoggerFactory loggerFactory)
|
public PhysicalFileResultExecutor(ILoggerFactory loggerFactory)
|
||||||
: base(CreateLogger<PhysicalFileResultExecutor>(loggerFactory))
|
: base(CreateLogger<PhysicalFileResultExecutor>(loggerFactory))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public virtual Task ExecuteAsync(ActionContext context, PhysicalFileResult result)
|
public virtual Task ExecuteAsync(ActionContext context, PhysicalFileResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -2,14 +2,16 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class RedirectResultExecutor
|
public class RedirectResultExecutor : IActionResultExecutor<RedirectResult>
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IUrlHelperFactory _urlHelperFactory;
|
private readonly IUrlHelperFactory _urlHelperFactory;
|
||||||
|
|
@ -30,7 +32,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
_urlHelperFactory = urlHelperFactory;
|
_urlHelperFactory = urlHelperFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Execute(ActionContext context, RedirectResult result)
|
/// <inheritdoc />
|
||||||
|
public virtual Task ExecuteAsync(ActionContext context, RedirectResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
|
|
@ -63,6 +66,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
{
|
{
|
||||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,15 +2,17 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Core;
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class RedirectToActionResultExecutor
|
public class RedirectToActionResultExecutor : IActionResultExecutor<RedirectToActionResult>
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IUrlHelperFactory _urlHelperFactory;
|
private readonly IUrlHelperFactory _urlHelperFactory;
|
||||||
|
|
@ -31,7 +33,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
_urlHelperFactory = urlHelperFactory;
|
_urlHelperFactory = urlHelperFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Execute(ActionContext context, RedirectToActionResult result)
|
/// <inheritdoc />
|
||||||
|
public virtual Task ExecuteAsync(ActionContext context, RedirectToActionResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
|
|
@ -69,6 +72,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
{
|
{
|
||||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,15 +2,17 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Core;
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class RedirectToPageResultExecutor
|
public class RedirectToPageResultExecutor : IActionResultExecutor<RedirectToPageResult>
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IUrlHelperFactory _urlHelperFactory;
|
private readonly IUrlHelperFactory _urlHelperFactory;
|
||||||
|
|
@ -31,7 +33,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
_urlHelperFactory = urlHelperFactory;
|
_urlHelperFactory = urlHelperFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Execute(ActionContext context, RedirectToPageResult result)
|
/// <inheritdoc />
|
||||||
|
public virtual Task ExecuteAsync(ActionContext context, RedirectToPageResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
|
|
@ -69,6 +72,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
{
|
{
|
||||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,15 +2,17 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Core;
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class RedirectToRouteResultExecutor
|
public class RedirectToRouteResultExecutor : IActionResultExecutor<RedirectToRouteResult>
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IUrlHelperFactory _urlHelperFactory;
|
private readonly IUrlHelperFactory _urlHelperFactory;
|
||||||
|
|
@ -31,7 +33,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
_urlHelperFactory = urlHelperFactory;
|
_urlHelperFactory = urlHelperFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Execute(ActionContext context, RedirectToRouteResult result)
|
/// <inheritdoc />
|
||||||
|
public virtual Task ExecuteAsync(ActionContext context, RedirectToRouteResult result)
|
||||||
{
|
{
|
||||||
var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context);
|
var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context);
|
||||||
|
|
||||||
|
|
@ -58,6 +61,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
{
|
{
|
||||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,9 +12,9 @@ using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class VirtualFileResultExecutor : FileResultExecutorBase
|
public class VirtualFileResultExecutor : FileResultExecutorBase , IActionResultExecutor<VirtualFileResult>
|
||||||
{
|
{
|
||||||
private readonly IHostingEnvironment _hostingEnvironment;
|
private readonly IHostingEnvironment _hostingEnvironment;
|
||||||
|
|
||||||
|
|
@ -29,6 +29,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
_hostingEnvironment = hostingEnvironment;
|
_hostingEnvironment = hostingEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public virtual Task ExecuteAsync(ActionContext context, VirtualFileResult result)
|
public virtual Task ExecuteAsync(ActionContext context, VirtualFileResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -2,9 +2,15 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Core;
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc
|
namespace Microsoft.AspNetCore.Mvc
|
||||||
{
|
{
|
||||||
|
|
@ -89,6 +95,19 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public IUrlHelper UrlHelper { get; set; }
|
public IUrlHelper UrlHelper { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
public override Task ExecuteResultAsync(ActionContext context)
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<LocalRedirectResult>>();
|
||||||
|
return executor.ExecuteAsync(context, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CS0809
|
||||||
|
[Obsolete("This implementation will be removed in a future release, use ExecuteResultAsync.")]
|
||||||
public override void ExecuteResult(ActionContext context)
|
public override void ExecuteResult(ActionContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -96,8 +115,32 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<LocalRedirectResultExecutor>();
|
var services = context.HttpContext.RequestServices;
|
||||||
executor.Execute(context, this);
|
var urlHelperFactory = services.GetRequiredService<IUrlHelperFactory>();
|
||||||
|
var logger = services.GetRequiredService<ILogger<LocalRedirectResult>>();
|
||||||
|
|
||||||
|
var urlHelper = UrlHelper ?? urlHelperFactory.GetUrlHelper(context);
|
||||||
|
|
||||||
|
// IsLocalUrl is called to handle Urls starting with '~/'.
|
||||||
|
if (!urlHelper.IsLocalUrl(Url))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(Resources.UrlNotLocal);
|
||||||
|
}
|
||||||
|
|
||||||
|
var destinationUrl = urlHelper.Content(Url);
|
||||||
|
logger.LocalRedirectResultExecuting(destinationUrl);
|
||||||
|
|
||||||
|
if (PreserveMethod)
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.StatusCode = Permanent ?
|
||||||
|
StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
|
||||||
|
context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.Redirect(destinationUrl, Permanent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#pragma warning restore CS0809
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
|
@ -33,10 +34,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
|
|
||||||
public override Task ExecuteResultAsync(ActionContext context)
|
public override Task ExecuteResultAsync(ActionContext context)
|
||||||
{
|
{
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<ObjectResultExecutor>();
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<ObjectResult>>();
|
||||||
var result = executor.ExecuteAsync(context, this);
|
return executor.ExecuteAsync(context, this);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
@ -74,7 +75,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<PhysicalFileResultExecutor>();
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<PhysicalFileResult>>();
|
||||||
return executor.ExecuteAsync(context, this);
|
return executor.ExecuteAsync(context, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,16 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Core;
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc
|
namespace Microsoft.AspNetCore.Mvc
|
||||||
{
|
{
|
||||||
|
|
@ -99,6 +105,19 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public IUrlHelper UrlHelper { get; set; }
|
public IUrlHelper UrlHelper { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
public override Task ExecuteResultAsync(ActionContext context)
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<RedirectResult>>();
|
||||||
|
return executor.ExecuteAsync(context, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CS0809
|
||||||
|
[Obsolete("This implementation will be removed in a future release, use ExecuteResultAsync.")]
|
||||||
public override void ExecuteResult(ActionContext context)
|
public override void ExecuteResult(ActionContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -106,8 +125,32 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<RedirectResultExecutor>();
|
var services = context.HttpContext.RequestServices;
|
||||||
executor.Execute(context, this);
|
var urlHelperFactory = services.GetRequiredService<IUrlHelperFactory>();
|
||||||
|
var logger = services.GetRequiredService<ILogger<RedirectResult>>();
|
||||||
|
|
||||||
|
var urlHelper = UrlHelper ?? urlHelperFactory.GetUrlHelper(context);
|
||||||
|
|
||||||
|
// IsLocalUrl is called to handle URLs starting with '~/'.
|
||||||
|
var destinationUrl = Url;
|
||||||
|
if (urlHelper.IsLocalUrl(destinationUrl))
|
||||||
|
{
|
||||||
|
destinationUrl = urlHelper.Content(Url);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.RedirectResultExecuting(destinationUrl);
|
||||||
|
|
||||||
|
if (PreserveMethod)
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.StatusCode = Permanent ?
|
||||||
|
StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
|
||||||
|
context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.Redirect(destinationUrl, Permanent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#pragma warning restore CS0809
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,10 +2,17 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc
|
namespace Microsoft.AspNetCore.Mvc
|
||||||
{
|
{
|
||||||
|
|
@ -165,6 +172,19 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public string Fragment { get; set; }
|
public string Fragment { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
public override Task ExecuteResultAsync(ActionContext context)
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<RedirectToActionResult>>();
|
||||||
|
return executor.ExecuteAsync(context, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CS0809
|
||||||
|
[Obsolete("This implementation will be removed in a future release, use ExecuteResultAsync.")]
|
||||||
public override void ExecuteResult(ActionContext context)
|
public override void ExecuteResult(ActionContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -172,8 +192,37 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<RedirectToActionResultExecutor>();
|
var services = context.HttpContext.RequestServices;
|
||||||
executor.Execute(context, this);
|
var urlHelperFactory = services.GetRequiredService<IUrlHelperFactory>();
|
||||||
|
var logger = services.GetRequiredService<ILogger<RedirectToActionResultExecutor>>();
|
||||||
|
|
||||||
|
var urlHelper = UrlHelper ?? urlHelperFactory.GetUrlHelper(context);
|
||||||
|
|
||||||
|
var destinationUrl = urlHelper.Action(
|
||||||
|
ActionName,
|
||||||
|
ControllerName,
|
||||||
|
RouteValues,
|
||||||
|
protocol: null,
|
||||||
|
host: null,
|
||||||
|
fragment: Fragment);
|
||||||
|
if (string.IsNullOrEmpty(destinationUrl))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(Resources.NoRoutesMatched);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.RedirectToActionResultExecuting(destinationUrl);
|
||||||
|
|
||||||
|
if (PreserveMethod)
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.StatusCode = Permanent ?
|
||||||
|
StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
|
||||||
|
context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.Redirect(destinationUrl, Permanent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#pragma warning restore CS0809
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -204,15 +206,15 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public string Host { get; set; }
|
public string Host { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void ExecuteResult(ActionContext context)
|
public override Task ExecuteResultAsync(ActionContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<RedirectToPageResultExecutor>();
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<RedirectToPageResult>>();
|
||||||
executor.Execute(context, this);
|
return executor.ExecuteAsync(context, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,17 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc
|
namespace Microsoft.AspNetCore.Mvc
|
||||||
{
|
{
|
||||||
|
|
@ -157,6 +164,19 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public string Fragment { get; set; }
|
public string Fragment { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
public override Task ExecuteResultAsync(ActionContext context)
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<RedirectToRouteResult>>();
|
||||||
|
return executor.ExecuteAsync(context, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CS0809
|
||||||
|
[Obsolete("This implementation will be removed in a future release, use ExecuteResultAsync.")]
|
||||||
public override void ExecuteResult(ActionContext context)
|
public override void ExecuteResult(ActionContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -164,8 +184,36 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<RedirectToRouteResultExecutor>();
|
var services = context.HttpContext.RequestServices;
|
||||||
executor.Execute(context, this);
|
var urlHelperFactory = services.GetRequiredService<IUrlHelperFactory>();
|
||||||
|
var logger = services.GetRequiredService<ILogger<RedirectToRouteResult>>();
|
||||||
|
|
||||||
|
var urlHelper = UrlHelper ?? urlHelperFactory.GetUrlHelper(context);
|
||||||
|
|
||||||
|
var destinationUrl = urlHelper.RouteUrl(
|
||||||
|
RouteName,
|
||||||
|
RouteValues,
|
||||||
|
protocol: null,
|
||||||
|
host: null,
|
||||||
|
fragment: Fragment);
|
||||||
|
if (string.IsNullOrEmpty(destinationUrl))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(Resources.NoRoutesMatched);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.RedirectToRouteResultExecuting(destinationUrl, RouteName);
|
||||||
|
|
||||||
|
if (PreserveMethod)
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.StatusCode = Permanent ?
|
||||||
|
StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
|
||||||
|
context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.Redirect(destinationUrl, Permanent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#pragma warning restore CS0809
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
|
@ -84,7 +85,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<VirtualFileResultExecutor>();
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<VirtualFileResult>>();
|
||||||
return executor.ExecuteAsync(context, this);
|
return executor.ExecuteAsync(context, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
||||||
|
|
@ -148,8 +149,8 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
// View Engine and related infrastructure
|
// View Engine and related infrastructure
|
||||||
//
|
//
|
||||||
services.TryAddSingleton<ICompositeViewEngine, CompositeViewEngine>();
|
services.TryAddSingleton<ICompositeViewEngine, CompositeViewEngine>();
|
||||||
services.TryAddSingleton<ViewResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<ViewResult>, ViewResultExecutor>();
|
||||||
services.TryAddSingleton<PartialViewResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<PartialViewResult>, PartialViewResultExecutor>();
|
||||||
|
|
||||||
// Support for activating ViewDataDictionary
|
// Support for activating ViewDataDictionary
|
||||||
services.TryAddEnumerable(
|
services.TryAddEnumerable(
|
||||||
|
|
@ -188,7 +189,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
services.TryAddSingleton<
|
services.TryAddSingleton<
|
||||||
IViewComponentDescriptorCollectionProvider,
|
IViewComponentDescriptorCollectionProvider,
|
||||||
DefaultViewComponentDescriptorCollectionProvider>();
|
DefaultViewComponentDescriptorCollectionProvider>();
|
||||||
services.TryAddSingleton<ViewComponentResultExecutor>();
|
services.TryAddSingleton<IActionResultExecutor<ViewComponentResult>, ViewComponentResultExecutor>();
|
||||||
|
|
||||||
services.TryAddSingleton<ViewComponentInvokerCache>();
|
services.TryAddSingleton<ViewComponentInvokerCache>();
|
||||||
services.TryAddTransient<IViewComponentDescriptorProvider, DefaultViewComponentDescriptorProvider>();
|
services.TryAddTransient<IViewComponentDescriptorProvider, DefaultViewComponentDescriptorProvider>();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||||
|
|
@ -57,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public string ContentType { get; set; }
|
public string ContentType { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task ExecuteResultAsync(ActionContext context)
|
public override Task ExecuteResultAsync(ActionContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
|
|
@ -65,16 +66,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
}
|
}
|
||||||
|
|
||||||
var services = context.HttpContext.RequestServices;
|
var services = context.HttpContext.RequestServices;
|
||||||
var executor = services.GetRequiredService<PartialViewResultExecutor>();
|
var executor = services.GetRequiredService<IActionResultExecutor<PartialViewResult>>();
|
||||||
|
return executor.ExecuteAsync(context, this);
|
||||||
var result = executor.FindView(context, this);
|
|
||||||
result.EnsureSuccessful(originalLocations: null);
|
|
||||||
|
|
||||||
var view = result.View;
|
|
||||||
using (view as IDisposable)
|
|
||||||
{
|
|
||||||
await executor.ExecuteAsync(context, view, this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
}
|
}
|
||||||
|
|
||||||
var services = context.HttpContext.RequestServices;
|
var services = context.HttpContext.RequestServices;
|
||||||
var executor = services.GetRequiredService<ViewComponentResultExecutor>();
|
var executor = services.GetRequiredService<IActionResultExecutor<ViewComponentResult>>();
|
||||||
return executor.ExecuteAsync(context, this);
|
return executor.ExecuteAsync(context, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,20 @@ using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds and executes an <see cref="IView"/> for a <see cref="PartialViewResult"/>.
|
/// Finds and executes an <see cref="IView"/> for a <see cref="PartialViewResult"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PartialViewResultExecutor : ViewExecutor
|
public class PartialViewResultExecutor : ViewExecutor, IActionResultExecutor<PartialViewResult>
|
||||||
{
|
{
|
||||||
private const string ActionNameKey = "action";
|
private const string ActionNameKey = "action";
|
||||||
|
|
||||||
|
|
@ -162,6 +164,29 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
viewResult.StatusCode);
|
viewResult.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public virtual async Task ExecuteAsync(ActionContext context, PartialViewResult result)
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
var viewEngineResult = FindView(context, result);
|
||||||
|
viewEngineResult.EnsureSuccessful(originalLocations: null);
|
||||||
|
|
||||||
|
var view = viewEngineResult.View;
|
||||||
|
using (view as IDisposable)
|
||||||
|
{
|
||||||
|
await ExecuteAsync(context, view, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static string GetActionName(ActionContext context)
|
private static string GetActionName(ActionContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -2,21 +2,22 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Html;
|
using Microsoft.AspNetCore.Html;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
{
|
{
|
||||||
public class ViewComponentResultExecutor
|
public class ViewComponentResultExecutor : IActionResultExecutor<ViewComponentResult>
|
||||||
{
|
{
|
||||||
private readonly HtmlEncoder _htmlEncoder;
|
private readonly HtmlEncoder _htmlEncoder;
|
||||||
private readonly HtmlHelperOptions _htmlHelperOptions;
|
private readonly HtmlHelperOptions _htmlHelperOptions;
|
||||||
|
|
@ -63,34 +64,35 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
_tempDataDictionaryFactory = tempDataDictionaryFactory;
|
_tempDataDictionaryFactory = tempDataDictionaryFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task ExecuteAsync(ActionContext context, ViewComponentResult viewComponentResult)
|
/// <inheritdoc />
|
||||||
|
public virtual async Task ExecuteAsync(ActionContext context, ViewComponentResult result)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewComponentResult == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(viewComponentResult));
|
throw new ArgumentNullException(nameof(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = context.HttpContext.Response;
|
var response = context.HttpContext.Response;
|
||||||
|
|
||||||
var viewData = viewComponentResult.ViewData;
|
var viewData = result.ViewData;
|
||||||
if (viewData == null)
|
if (viewData == null)
|
||||||
{
|
{
|
||||||
viewData = new ViewDataDictionary(_modelMetadataProvider, context.ModelState);
|
viewData = new ViewDataDictionary(_modelMetadataProvider, context.ModelState);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tempData = viewComponentResult.TempData;
|
var tempData = result.TempData;
|
||||||
if (tempData == null)
|
if (tempData == null)
|
||||||
{
|
{
|
||||||
tempData = _tempDataDictionaryFactory.GetTempData(context.HttpContext);
|
tempData = _tempDataDictionaryFactory.GetTempData(context.HttpContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseContentTypeHelper.ResolveContentTypeAndEncoding(
|
ResponseContentTypeHelper.ResolveContentTypeAndEncoding(
|
||||||
viewComponentResult.ContentType,
|
result.ContentType,
|
||||||
response.ContentType,
|
response.ContentType,
|
||||||
ViewExecutor.DefaultContentType,
|
ViewExecutor.DefaultContentType,
|
||||||
out var resolvedContentType,
|
out var resolvedContentType,
|
||||||
|
|
@ -98,9 +100,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
|
|
||||||
response.ContentType = resolvedContentType;
|
response.ContentType = resolvedContentType;
|
||||||
|
|
||||||
if (viewComponentResult.StatusCode != null)
|
if (result.StatusCode != null)
|
||||||
{
|
{
|
||||||
response.StatusCode = viewComponentResult.StatusCode.Value;
|
response.StatusCode = result.StatusCode.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var writer = new HttpResponseStreamWriter(response.Body, resolvedContentTypeEncoding))
|
using (var writer = new HttpResponseStreamWriter(response.Body, resolvedContentTypeEncoding))
|
||||||
|
|
@ -117,9 +119,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
var viewComponentHelper = context.HttpContext.RequestServices.GetRequiredService<IViewComponentHelper>();
|
var viewComponentHelper = context.HttpContext.RequestServices.GetRequiredService<IViewComponentHelper>();
|
||||||
(viewComponentHelper as IViewContextAware)?.Contextualize(viewContext);
|
(viewComponentHelper as IViewContextAware)?.Contextualize(viewContext);
|
||||||
|
|
||||||
var result = await GetViewComponentResult(viewComponentHelper, _logger, viewComponentResult);
|
var viewComponentResult = await GetViewComponentResult(viewComponentHelper, _logger, result);
|
||||||
|
viewComponentResult.WriteTo(writer, _htmlEncoder);
|
||||||
result.WriteTo(writer, _htmlEncoder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6,18 +6,20 @@ using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds and executes an <see cref="IView"/> for a <see cref="ViewResult"/>.
|
/// Finds and executes an <see cref="IView"/> for a <see cref="ViewResult"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ViewResultExecutor : ViewExecutor
|
public class ViewResultExecutor : ViewExecutor, IActionResultExecutor<ViewResult>
|
||||||
{
|
{
|
||||||
private const string ActionNameKey = "action";
|
private const string ActionNameKey = "action";
|
||||||
|
|
||||||
|
|
@ -141,39 +143,35 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc />
|
||||||
/// Executes the <see cref="IView"/> asynchronously.
|
public async Task ExecuteAsync(ActionContext context, ViewResult result)
|
||||||
/// </summary>
|
|
||||||
/// <param name="actionContext">The <see cref="ActionContext"/> associated with the current request.</param>
|
|
||||||
/// <param name="view">The <see cref="IView"/>.</param>
|
|
||||||
/// <param name="viewResult">The <see cref="ViewResult"/>.</param>
|
|
||||||
/// <returns>A <see cref="Task"/> which will complete when view execution is completed.</returns>
|
|
||||||
public virtual Task ExecuteAsync(ActionContext actionContext, IView view, ViewResult viewResult)
|
|
||||||
{
|
{
|
||||||
if (actionContext == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(actionContext));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(view));
|
throw new ArgumentNullException(nameof(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewResult == null)
|
var viewEngineResult = FindView(context, result);
|
||||||
|
viewEngineResult.EnsureSuccessful(originalLocations: null);
|
||||||
|
|
||||||
|
var view = viewEngineResult.View;
|
||||||
|
using (view as IDisposable)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(viewResult));
|
Logger.ViewResultExecuting(view);
|
||||||
|
|
||||||
|
await ExecuteAsync(
|
||||||
|
context,
|
||||||
|
view,
|
||||||
|
result.ViewData,
|
||||||
|
result.TempData,
|
||||||
|
result.ContentType,
|
||||||
|
result.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.ViewResultExecuting(view);
|
|
||||||
|
|
||||||
return ExecuteAsync(
|
|
||||||
actionContext,
|
|
||||||
view,
|
|
||||||
viewResult.ViewData,
|
|
||||||
viewResult.TempData,
|
|
||||||
viewResult.ContentType,
|
|
||||||
viewResult.StatusCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetActionName(ActionContext context)
|
private static string GetActionName(ActionContext context)
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||||
|
|
@ -64,17 +65,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
var services = context.HttpContext.RequestServices;
|
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<ViewResult>>();
|
||||||
var executor = services.GetRequiredService<ViewResultExecutor>();
|
await executor.ExecuteAsync(context, this);
|
||||||
|
|
||||||
var result = executor.FindView(context, this);
|
|
||||||
result.EnsureSuccessful(originalLocations: null);
|
|
||||||
|
|
||||||
var view = result.View;
|
|
||||||
using (view as IDisposable)
|
|
||||||
{
|
|
||||||
await executor.ExecuteAsync(context, view, this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -273,7 +274,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
var options = new TestOptionsManager<MvcOptions>();
|
var options = new TestOptionsManager<MvcOptions>();
|
||||||
options.Value.OutputFormatters.Add(formatter.Object);
|
options.Value.OutputFormatters.Add(formatter.Object);
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
|
@ -182,7 +183,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
var options = new TestOptionsManager<MvcOptions>();
|
var options = new TestOptionsManager<MvcOptions>();
|
||||||
options.Value.OutputFormatters.Add(formatter.Object);
|
options.Value.OutputFormatters.Add(formatter.Object);
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -138,7 +139,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
||||||
var options = new TestOptionsManager<MvcOptions>();
|
var options = new TestOptionsManager<MvcOptions>();
|
||||||
options.Value.OutputFormatters.Add(formatter.Object);
|
options.Value.OutputFormatters.Add(formatter.Object);
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
||||||
|
|
@ -269,7 +270,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
.Returns(new char[DefaultCharacterChunkSize]);
|
.Returns(new char[DefaultCharacterChunkSize]);
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ContentResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ContentResult>>(new ContentResultExecutor(
|
||||||
new Logger<ContentResultExecutor>(NullLoggerFactory.Instance),
|
new Logger<ContentResultExecutor>(NullLoggerFactory.Instance),
|
||||||
new MemoryPoolHttpResponseStreamWriterFactory(ArrayPool<byte>.Shared, charArrayPool.Object)));
|
new MemoryPoolHttpResponseStreamWriterFactory(ArrayPool<byte>.Shared, charArrayPool.Object)));
|
||||||
return services;
|
return services;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
ArrayPool<char>.Shared));
|
ArrayPool<char>.Shared));
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
|
@ -110,7 +111,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
ArrayPool<char>.Shared));
|
ArrayPool<char>.Shared));
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
ArrayPool<char>.Shared));
|
ArrayPool<char>.Shared));
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -422,7 +423,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
private static IServiceCollection CreateServices()
|
private static IServiceCollection CreateServices()
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton<FileContentResultExecutor>();
|
services.AddSingleton<IActionResultExecutor<FileContentResult>, FileContentResultExecutor>();
|
||||||
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -527,7 +528,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
private static IServiceCollection CreateServices()
|
private static IServiceCollection CreateServices()
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton<FileStreamResultExecutor>();
|
services.AddSingleton<IActionResultExecutor<FileStreamResult>, FileStreamResultExecutor>();
|
||||||
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
@ -75,7 +76,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
ArrayPool<char>.Shared));
|
ArrayPool<char>.Shared));
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -76,7 +77,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
ArrayPool<char>.Shared));
|
ArrayPool<char>.Shared));
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -16,7 +17,7 @@ using Microsoft.Extensions.Primitives;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
public class ObjectResultExecutorTest
|
public class ObjectResultExecutorTest
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1602,7 +1602,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
||||||
services.AddSingleton<IOptions<MvcOptions>>(mvcOptionsAccessor);
|
services.AddSingleton<IOptions<MvcOptions>>(mvcOptionsAccessor);
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
mvcOptionsAccessor,
|
mvcOptionsAccessor,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Internal;
|
using Microsoft.AspNetCore.Http.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -63,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Execute_ReturnsExpectedValues()
|
public async Task Execute_ReturnsExpectedValues()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var appRoot = "/";
|
var appRoot = "/";
|
||||||
|
|
@ -78,7 +80,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
var result = new LocalRedirectResult(contentPath);
|
var result = new LocalRedirectResult(contentPath);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
result.ExecuteResult(actionContext);
|
await result.ExecuteResultAsync(actionContext);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
httpResponse.Verify();
|
httpResponse.Verify();
|
||||||
|
|
@ -87,7 +89,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("", "Home/About", "/Home/About")]
|
[InlineData("", "Home/About", "/Home/About")]
|
||||||
[InlineData("/myapproot", "http://www.example.com", "/test")]
|
[InlineData("/myapproot", "http://www.example.com", "/test")]
|
||||||
public void Execute_Throws_ForNonLocalUrl(
|
public async Task Execute_Throws_ForNonLocalUrl(
|
||||||
string appRoot,
|
string appRoot,
|
||||||
string contentPath,
|
string contentPath,
|
||||||
string expectedPath)
|
string expectedPath)
|
||||||
|
|
@ -102,7 +104,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
var result = new LocalRedirectResult(contentPath);
|
var result = new LocalRedirectResult(contentPath);
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
var exception = Assert.Throws<InvalidOperationException>(() => result.ExecuteResult(actionContext));
|
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() => result.ExecuteResultAsync(actionContext));
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
"The supplied URL is not local. A URL with an absolute path is considered local if it does not " +
|
"The supplied URL is not local. A URL with an absolute path is considered local if it does not " +
|
||||||
"have a host/authority part. URLs using virtual paths ('~/') are also local.",
|
"have a host/authority part. URLs using virtual paths ('~/') are also local.",
|
||||||
|
|
@ -120,7 +122,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
private static IServiceProvider GetServiceProvider()
|
private static IServiceProvider GetServiceProvider()
|
||||||
{
|
{
|
||||||
var serviceCollection = new ServiceCollection();
|
var serviceCollection = new ServiceCollection();
|
||||||
serviceCollection.AddSingleton<LocalRedirectResultExecutor>();
|
serviceCollection.AddSingleton<IActionResultExecutor<LocalRedirectResult>, LocalRedirectResultExecutor>();
|
||||||
serviceCollection.AddSingleton<IUrlHelperFactory, UrlHelperFactory>();
|
serviceCollection.AddSingleton<IUrlHelperFactory, UrlHelperFactory>();
|
||||||
serviceCollection.AddTransient<ILoggerFactory, LoggerFactory>();
|
serviceCollection.AddTransient<ILoggerFactory, LoggerFactory>();
|
||||||
return serviceCollection.BuildServiceProvider();
|
return serviceCollection.BuildServiceProvider();
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -63,7 +64,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
private static IServiceProvider CreateServices()
|
private static IServiceProvider CreateServices()
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
new TestOptionsManager<MvcOptions>(),
|
new TestOptionsManager<MvcOptions>(),
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Internal;
|
using Microsoft.AspNetCore.Http.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -65,7 +67,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("", "/Home/About", "/Home/About")]
|
[InlineData("", "/Home/About", "/Home/About")]
|
||||||
[InlineData("/myapproot", "/test", "/test")]
|
[InlineData("/myapproot", "/test", "/test")]
|
||||||
public void Execute_ReturnsContentPath_WhenItDoesNotStartWithTilde(
|
public async Task Execute_ReturnsContentPath_WhenItDoesNotStartWithTilde(
|
||||||
string appRoot,
|
string appRoot,
|
||||||
string contentPath,
|
string contentPath,
|
||||||
string expectedPath)
|
string expectedPath)
|
||||||
|
|
@ -80,7 +82,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
var result = new RedirectResult(contentPath);
|
var result = new RedirectResult(contentPath);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
result.ExecuteResult(actionContext);
|
await result.ExecuteResultAsync(actionContext);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// Verifying if Redirect was called with the specific Url and parameter flag.
|
// Verifying if Redirect was called with the specific Url and parameter flag.
|
||||||
|
|
@ -93,7 +95,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
[InlineData("/", "~/", "/")]
|
[InlineData("/", "~/", "/")]
|
||||||
[InlineData("", "~/Home/About", "/Home/About")]
|
[InlineData("", "~/Home/About", "/Home/About")]
|
||||||
[InlineData("/myapproot", "~/", "/myapproot/")]
|
[InlineData("/myapproot", "~/", "/myapproot/")]
|
||||||
public void Execute_ReturnsAppRelativePath_WhenItStartsWithTilde(
|
public async Task Execute_ReturnsAppRelativePath_WhenItStartsWithTilde(
|
||||||
string appRoot,
|
string appRoot,
|
||||||
string contentPath,
|
string contentPath,
|
||||||
string expectedPath)
|
string expectedPath)
|
||||||
|
|
@ -108,7 +110,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
var result = new RedirectResult(contentPath);
|
var result = new RedirectResult(contentPath);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
result.ExecuteResult(actionContext);
|
await result.ExecuteResultAsync(actionContext);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// Verifying if Redirect was called with the specific Url and parameter flag.
|
// Verifying if Redirect was called with the specific Url and parameter flag.
|
||||||
|
|
@ -128,7 +130,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
private static IServiceProvider GetServiceProvider()
|
private static IServiceProvider GetServiceProvider()
|
||||||
{
|
{
|
||||||
var serviceCollection = new ServiceCollection();
|
var serviceCollection = new ServiceCollection();
|
||||||
serviceCollection.AddSingleton<RedirectResultExecutor>();
|
serviceCollection.AddSingleton<IActionResultExecutor<RedirectResult>, RedirectResultExecutor>();
|
||||||
serviceCollection.AddSingleton<IUrlHelperFactory, UrlHelperFactory>();
|
serviceCollection.AddSingleton<IUrlHelperFactory, UrlHelperFactory>();
|
||||||
serviceCollection.AddTransient<ILoggerFactory, LoggerFactory>();
|
serviceCollection.AddTransient<ILoggerFactory, LoggerFactory>();
|
||||||
return serviceCollection.BuildServiceProvider();
|
return serviceCollection.BuildServiceProvider();
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
private static IServiceCollection CreateServices()
|
private static IServiceCollection CreateServices()
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton<RedirectToActionResultExecutor>();
|
services.AddSingleton<IActionResultExecutor<RedirectToActionResult>, RedirectToActionResultExecutor>();
|
||||||
services.AddSingleton<IUrlHelperFactory, UrlHelperFactory>();
|
services.AddSingleton<IUrlHelperFactory, UrlHelperFactory>();
|
||||||
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
||||||
return services;
|
return services;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
|
|
@ -297,7 +298,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
private static IServiceProvider CreateServices(IUrlHelperFactory factory = null)
|
private static IServiceProvider CreateServices(IUrlHelperFactory factory = null)
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton<RedirectToPageResultExecutor>();
|
services.AddSingleton<IActionResultExecutor<RedirectToPageResult>, RedirectToPageResultExecutor>();
|
||||||
|
|
||||||
if (factory != null)
|
if (factory != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -179,7 +180,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
private static IServiceCollection CreateServices(IUrlHelperFactory factory = null)
|
private static IServiceCollection CreateServices(IUrlHelperFactory factory = null)
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton<RedirectToRouteResultExecutor>();
|
services.AddSingleton<IActionResultExecutor<RedirectToRouteResult>, RedirectToRouteResultExecutor>();
|
||||||
|
|
||||||
if (factory != null)
|
if (factory != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -73,7 +74,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
httpContext.Response.Body = new MemoryStream();
|
httpContext.Response.Body = new MemoryStream();
|
||||||
httpContext.RequestServices = new ServiceCollection()
|
httpContext.RequestServices = new ServiceCollection()
|
||||||
.AddSingleton(appEnvironment.Object)
|
.AddSingleton(appEnvironment.Object)
|
||||||
.AddTransient<TestVirtualFileResultExecutor>()
|
.AddTransient<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>()
|
||||||
.AddTransient<ILoggerFactory, LoggerFactory>()
|
.AddTransient<ILoggerFactory, LoggerFactory>()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
@ -117,7 +118,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
httpContext.Response.Body = new MemoryStream();
|
httpContext.Response.Body = new MemoryStream();
|
||||||
httpContext.RequestServices = new ServiceCollection()
|
httpContext.RequestServices = new ServiceCollection()
|
||||||
.AddSingleton(appEnvironment.Object)
|
.AddSingleton(appEnvironment.Object)
|
||||||
.AddTransient<TestVirtualFileResultExecutor>()
|
.AddTransient<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>()
|
||||||
.AddTransient<ILoggerFactory, LoggerFactory>()
|
.AddTransient<ILoggerFactory, LoggerFactory>()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
@ -162,7 +163,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
httpContext.Response.Body = new MemoryStream();
|
httpContext.Response.Body = new MemoryStream();
|
||||||
httpContext.RequestServices = new ServiceCollection()
|
httpContext.RequestServices = new ServiceCollection()
|
||||||
.AddSingleton(appEnvironment.Object)
|
.AddSingleton(appEnvironment.Object)
|
||||||
.AddTransient<TestVirtualFileResultExecutor>()
|
.AddTransient<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>()
|
||||||
.AddTransient<ILoggerFactory, LoggerFactory>()
|
.AddTransient<ILoggerFactory, LoggerFactory>()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
@ -207,7 +208,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
httpContext.Response.Body = new MemoryStream();
|
httpContext.Response.Body = new MemoryStream();
|
||||||
httpContext.RequestServices = new ServiceCollection()
|
httpContext.RequestServices = new ServiceCollection()
|
||||||
.AddSingleton(appEnvironment.Object)
|
.AddSingleton(appEnvironment.Object)
|
||||||
.AddTransient<TestVirtualFileResultExecutor>()
|
.AddTransient<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>()
|
||||||
.AddTransient<ILoggerFactory, LoggerFactory>()
|
.AddTransient<ILoggerFactory, LoggerFactory>()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
@ -250,7 +251,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
httpContext.Response.Body = new MemoryStream();
|
httpContext.Response.Body = new MemoryStream();
|
||||||
httpContext.RequestServices = new ServiceCollection()
|
httpContext.RequestServices = new ServiceCollection()
|
||||||
.AddSingleton(appEnvironment.Object)
|
.AddSingleton(appEnvironment.Object)
|
||||||
.AddTransient<TestVirtualFileResultExecutor>()
|
.AddTransient<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>()
|
||||||
.AddTransient<ILoggerFactory, LoggerFactory>()
|
.AddTransient<ILoggerFactory, LoggerFactory>()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
@ -292,7 +293,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
httpContext.Response.Body = new MemoryStream();
|
httpContext.Response.Body = new MemoryStream();
|
||||||
httpContext.RequestServices = new ServiceCollection()
|
httpContext.RequestServices = new ServiceCollection()
|
||||||
.AddSingleton(appEnvironment.Object)
|
.AddSingleton(appEnvironment.Object)
|
||||||
.AddTransient<TestVirtualFileResultExecutor>()
|
.AddTransient<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>()
|
||||||
.AddTransient<ILoggerFactory, LoggerFactory>()
|
.AddTransient<ILoggerFactory, LoggerFactory>()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
@ -334,7 +335,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
httpContext.Response.Body = new MemoryStream();
|
httpContext.Response.Body = new MemoryStream();
|
||||||
httpContext.RequestServices = new ServiceCollection()
|
httpContext.RequestServices = new ServiceCollection()
|
||||||
.AddSingleton(appEnvironment.Object)
|
.AddSingleton(appEnvironment.Object)
|
||||||
.AddTransient<TestVirtualFileResultExecutor>()
|
.AddTransient<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>()
|
||||||
.AddTransient<ILoggerFactory, LoggerFactory>()
|
.AddTransient<ILoggerFactory, LoggerFactory>()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
@ -376,7 +377,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
httpContext.Response.Body = new MemoryStream();
|
httpContext.Response.Body = new MemoryStream();
|
||||||
httpContext.RequestServices = new ServiceCollection()
|
httpContext.RequestServices = new ServiceCollection()
|
||||||
.AddSingleton(appEnvironment.Object)
|
.AddSingleton(appEnvironment.Object)
|
||||||
.AddTransient<TestVirtualFileResultExecutor>()
|
.AddTransient<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>()
|
||||||
.AddTransient<ILoggerFactory, LoggerFactory>()
|
.AddTransient<ILoggerFactory, LoggerFactory>()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
|
|
@ -464,7 +465,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
.Returns(GetFileProvider(path));
|
.Returns(GetFileProvider(path));
|
||||||
httpContext.RequestServices = new ServiceCollection()
|
httpContext.RequestServices = new ServiceCollection()
|
||||||
.AddSingleton(appEnvironment.Object)
|
.AddSingleton(appEnvironment.Object)
|
||||||
.AddTransient<TestVirtualFileResultExecutor>()
|
.AddTransient<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>()
|
||||||
.AddTransient<ILoggerFactory, LoggerFactory>()
|
.AddTransient<ILoggerFactory, LoggerFactory>()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
@ -665,7 +666,12 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
|
|
||||||
var hostingEnvironment = new Mock<IHostingEnvironment>();
|
var hostingEnvironment = new Mock<IHostingEnvironment>();
|
||||||
|
|
||||||
services.AddSingleton(executorType ?? typeof(TestVirtualFileResultExecutor));
|
services.AddSingleton<IActionResultExecutor<VirtualFileResult>, TestVirtualFileResultExecutor>();
|
||||||
|
if (executorType != null)
|
||||||
|
{
|
||||||
|
services.AddSingleton(typeof(IActionResultExecutor<VirtualFileResult>), executorType);
|
||||||
|
}
|
||||||
|
|
||||||
services.AddSingleton<IHostingEnvironment>(hostingEnvironment.Object);
|
services.AddSingleton<IHostingEnvironment>(hostingEnvironment.Object);
|
||||||
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
|
||||||
|
|
||||||
|
|
@ -708,7 +714,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
|
|
||||||
public override Task ExecuteResultAsync(ActionContext context)
|
public override Task ExecuteResultAsync(ActionContext context)
|
||||||
{
|
{
|
||||||
var executor = context.HttpContext.RequestServices.GetRequiredService<TestVirtualFileResultExecutor>();
|
var executor = (TestVirtualFileResultExecutor)context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<VirtualFileResult>>();
|
||||||
executor.IsAscii = IsAscii;
|
executor.IsAscii = IsAscii;
|
||||||
return executor.ExecuteAsync(context, this);
|
return executor.ExecuteAsync(context, this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
|
|
@ -226,7 +227,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
new EmptyModelMetadataProvider());
|
new EmptyModelMetadataProvider());
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(viewExecutor);
|
services.AddSingleton<IActionResultExecutor<PartialViewResult>>(viewExecutor);
|
||||||
|
|
||||||
var httpContext = new DefaultHttpContext();
|
var httpContext = new DefaultHttpContext();
|
||||||
httpContext.RequestServices = services.BuildServiceProvider();
|
httpContext.RequestServices = services.BuildServiceProvider();
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Html;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
||||||
|
|
@ -579,7 +580,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
services.AddSingleton<ITempDataProvider, SessionStateTempDataProvider>();
|
services.AddSingleton<ITempDataProvider, SessionStateTempDataProvider>();
|
||||||
services.AddSingleton<HtmlEncoder, HtmlTestEncoder>();
|
services.AddSingleton<HtmlEncoder, HtmlTestEncoder>();
|
||||||
services.AddSingleton<IViewBufferScope, TestViewBufferScope>();
|
services.AddSingleton<IViewBufferScope, TestViewBufferScope>();
|
||||||
services.AddSingleton<ViewComponentResultExecutor>();
|
services.AddSingleton<IActionResultExecutor<ViewComponentResult>, ViewComponentResultExecutor>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
|
@ -16,7 +15,7 @@ using Microsoft.Net.Http.Headers;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
{
|
{
|
||||||
public class PartialViewResultExecutorTest
|
public class PartialViewResultExecutorTest
|
||||||
{
|
{
|
||||||
|
|
@ -5,7 +5,6 @@ using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
|
|
@ -15,7 +14,7 @@ using Microsoft.Net.Http.Headers;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
{
|
{
|
||||||
public class ViewResultExecutorTest
|
public class ViewResultExecutorTest
|
||||||
{
|
{
|
||||||
|
|
@ -268,7 +267,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await executor.ExecuteAsync(context, Mock.Of<IView>(), viewResult);
|
await executor.ExecuteAsync(context, viewResult);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("application/x-my-content-type", context.HttpContext.Response.ContentType);
|
Assert.Equal("application/x-my-content-type", context.HttpContext.Response.ContentType);
|
||||||
|
|
@ -292,7 +291,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await executor.ExecuteAsync(context, Mock.Of<IView>(), viewResult);
|
await executor.ExecuteAsync(context, viewResult);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(404, context.HttpContext.Response.StatusCode);
|
Assert.Equal(404, context.HttpContext.Response.StatusCode);
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
|
|
@ -238,7 +239,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
new EmptyModelMetadataProvider());
|
new EmptyModelMetadataProvider());
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(viewExecutor);
|
services.AddSingleton<IActionResultExecutor<ViewResult>>(viewExecutor);
|
||||||
|
|
||||||
var httpContext = new DefaultHttpContext();
|
var httpContext = new DefaultHttpContext();
|
||||||
httpContext.RequestServices = services.BuildServiceProvider();
|
httpContext.RequestServices = services.BuildServiceProvider();
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -74,7 +75,7 @@ namespace System.Web.Http
|
||||||
ArrayPool<char>.Shared));
|
ArrayPool<char>.Shared));
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -74,7 +75,7 @@ namespace System.Web.Http
|
||||||
ArrayPool<char>.Shared));
|
ArrayPool<char>.Shared));
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
@ -87,7 +88,7 @@ namespace System.Web.Http
|
||||||
ArrayPool<char>.Shared));
|
ArrayPool<char>.Shared));
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -75,7 +76,7 @@ namespace System.Web.Http
|
||||||
ArrayPool<char>.Shared));
|
ArrayPool<char>.Shared));
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(new ObjectResultExecutor(
|
services.AddSingleton<IActionResultExecutor<ObjectResult>>(new ObjectResultExecutor(
|
||||||
options,
|
options,
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLoggerFactory.Instance));
|
NullLoggerFactory.Instance));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue