diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ContentResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/ContentResult.cs index 9051496640..65ad59bf47 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ContentResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ContentResult.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; @@ -32,7 +33,7 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); + var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs index 223ada2cdd..bc2a5c992d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs @@ -250,17 +250,17 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddSingleton(); services.TryAddSingleton(ArrayPool.Shared); services.TryAddSingleton(ArrayPool.Shared); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); + services.TryAddSingleton, ObjectResultExecutor>(); + services.TryAddSingleton, PhysicalFileResultExecutor>(); + services.TryAddSingleton, VirtualFileResultExecutor>(); + services.TryAddSingleton, FileStreamResultExecutor>(); + services.TryAddSingleton, FileContentResultExecutor>(); + services.TryAddSingleton, RedirectResultExecutor>(); + services.TryAddSingleton, LocalRedirectResultExecutor>(); + services.TryAddSingleton, RedirectToActionResultExecutor>(); + services.TryAddSingleton, RedirectToRouteResultExecutor>(); + services.TryAddSingleton, RedirectToPageResultExecutor>(); + services.TryAddSingleton, ContentResultExecutor>(); // // Route Handlers diff --git a/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs index 476eace53e..99385c9bd3 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Net.Http.Headers; @@ -76,7 +77,7 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); + var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs index bd0367393a..486069a5ea 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Net.Http.Headers; @@ -73,7 +74,7 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); + var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ContentResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ContentResultExecutor.cs similarity index 93% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/ContentResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ContentResultExecutor.cs index c296700859..7a1f333b3a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ContentResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ContentResultExecutor.cs @@ -4,11 +4,12 @@ using System; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class ContentResultExecutor + public class ContentResultExecutor : IActionResultExecutor { private const string DefaultContentType = "text/plain; charset=utf-8"; private readonly ILogger _logger; @@ -20,6 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _httpResponseStreamWriterFactory = httpResponseStreamWriterFactory; } + /// public virtual async Task ExecuteAsync(ActionContext context, ContentResult result) { if (context == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileContentResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileContentResultExecutor.cs similarity index 94% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/FileContentResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileContentResultExecutor.cs index f6763ac01f..af8cfe17cf 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileContentResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileContentResultExecutor.cs @@ -7,15 +7,16 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class FileContentResultExecutor : FileResultExecutorBase + public class FileContentResultExecutor : FileResultExecutorBase, IActionResultExecutor { public FileContentResultExecutor(ILoggerFactory loggerFactory) : base(CreateLogger(loggerFactory)) { } + /// public virtual Task ExecuteAsync(ActionContext context, FileContentResult result) { if (context == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileResultExecutorBase.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs similarity index 99% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/FileResultExecutorBase.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs index 8b3b429ac7..51ed06e19e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileResultExecutorBase.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs @@ -10,10 +10,11 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Http.Headers; using Microsoft.AspNetCore.Internal; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { public class FileResultExecutorBase { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileStreamResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileStreamResultExecutor.cs similarity index 94% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/FileStreamResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileStreamResultExecutor.cs index 363af243c3..97bda5988f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileStreamResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileStreamResultExecutor.cs @@ -6,15 +6,16 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class FileStreamResultExecutor : FileResultExecutorBase + public class FileStreamResultExecutor : FileResultExecutorBase, IActionResultExecutor { public FileStreamResultExecutor(ILoggerFactory loggerFactory) : base(CreateLogger(loggerFactory)) { } + /// public virtual Task ExecuteAsync(ActionContext context, FileStreamResult result) { if (context == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/IActionResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/IActionResultExecutor.cs new file mode 100644 index 0000000000..3a4e398c5e --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/IActionResultExecutor.cs @@ -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 +{ + /// + /// Defines an interface for a service which can execute a particular kind of by + /// manipulating the . + /// + /// The type of . + /// + /// Implementions of are typically called by the + /// method of the corresponding action result type. + /// Implementations should be registered as singleton services. + /// + public interface IActionResultExecutor where TResult : IActionResult + { + /// + /// Asynchronously excecutes the action result, by modifying the . + /// + /// The associated with the current request."/> + /// The action result to execute. + /// A which represents the asynchronous operation. + Task ExecuteAsync(ActionContext context, TResult result); + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/LocalRedirectResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/LocalRedirectResultExecutor.cs similarity index 85% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/LocalRedirectResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/LocalRedirectResultExecutor.cs index d8dc95a2c1..9ae7a3bda5 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/LocalRedirectResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/LocalRedirectResultExecutor.cs @@ -2,15 +2,17 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class LocalRedirectResultExecutor + public class LocalRedirectResultExecutor : IActionResultExecutor { private readonly ILogger _logger; private readonly IUrlHelperFactory _urlHelperFactory; @@ -31,7 +33,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal _urlHelperFactory = urlHelperFactory; } - public virtual void Execute(ActionContext context, LocalRedirectResult result) + /// + public virtual Task ExecuteAsync(ActionContext context, LocalRedirectResult result) { if (context == null) { @@ -64,6 +67,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal { context.HttpContext.Response.Redirect(destinationUrl, result.Permanent); } + + return Task.CompletedTask; } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ObjectResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ObjectResultExecutor.cs similarity index 99% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/ObjectResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ObjectResultExecutor.cs index 19e9722fba..fb767322a7 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ObjectResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ObjectResultExecutor.cs @@ -11,17 +11,18 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Formatters.Internal; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { /// /// Executes an to write to the response. /// - public class ObjectResultExecutor + public class ObjectResultExecutor : IActionResultExecutor { /// /// Creates a new . diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/PhysicalFileResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/PhysicalFileResultExecutor.cs similarity index 97% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/PhysicalFileResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/PhysicalFileResultExecutor.cs index 889630c68e..c2ea1a624d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/PhysicalFileResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/PhysicalFileResultExecutor.cs @@ -10,15 +10,16 @@ using Microsoft.AspNetCore.Mvc.Core; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class PhysicalFileResultExecutor : FileResultExecutorBase + public class PhysicalFileResultExecutor : FileResultExecutorBase, IActionResultExecutor { public PhysicalFileResultExecutor(ILoggerFactory loggerFactory) : base(CreateLogger(loggerFactory)) { } + /// public virtual Task ExecuteAsync(ActionContext context, PhysicalFileResult result) { if (context == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectResultExecutor.cs similarity index 85% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectResultExecutor.cs index 503ce41ef1..e8f80b17da 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectResultExecutor.cs @@ -2,14 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class RedirectResultExecutor + public class RedirectResultExecutor : IActionResultExecutor { private readonly ILogger _logger; private readonly IUrlHelperFactory _urlHelperFactory; @@ -30,7 +32,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal _urlHelperFactory = urlHelperFactory; } - public virtual void Execute(ActionContext context, RedirectResult result) + /// + public virtual Task ExecuteAsync(ActionContext context, RedirectResult result) { if (context == null) { @@ -63,6 +66,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal { context.HttpContext.Response.Redirect(destinationUrl, result.Permanent); } + + return Task.CompletedTask; } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectToActionResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToActionResultExecutor.cs similarity index 86% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectToActionResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToActionResultExecutor.cs index 9ffef08c41..b1b131274b 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectToActionResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToActionResultExecutor.cs @@ -2,15 +2,17 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class RedirectToActionResultExecutor + public class RedirectToActionResultExecutor : IActionResultExecutor { private readonly ILogger _logger; private readonly IUrlHelperFactory _urlHelperFactory; @@ -31,7 +33,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal _urlHelperFactory = urlHelperFactory; } - public virtual void Execute(ActionContext context, RedirectToActionResult result) + /// + public virtual Task ExecuteAsync(ActionContext context, RedirectToActionResult result) { if (context == null) { @@ -69,6 +72,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal { context.HttpContext.Response.Redirect(destinationUrl, result.Permanent); } + + return Task.CompletedTask; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectToPageResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToPageResultExecutor.cs similarity index 86% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectToPageResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToPageResultExecutor.cs index b6c309c6f1..ee1c060e87 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectToPageResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToPageResultExecutor.cs @@ -2,15 +2,17 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class RedirectToPageResultExecutor + public class RedirectToPageResultExecutor : IActionResultExecutor { private readonly ILogger _logger; private readonly IUrlHelperFactory _urlHelperFactory; @@ -31,7 +33,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal _urlHelperFactory = urlHelperFactory; } - public virtual void Execute(ActionContext context, RedirectToPageResult result) + /// + public virtual Task ExecuteAsync(ActionContext context, RedirectToPageResult result) { if (context == null) { @@ -69,6 +72,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal { context.HttpContext.Response.Redirect(destinationUrl, result.Permanent); } + + return Task.CompletedTask; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectToRouteResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToRouteResultExecutor.cs similarity index 84% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectToRouteResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToRouteResultExecutor.cs index 5b16b3683b..04e15feacf 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/RedirectToRouteResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToRouteResultExecutor.cs @@ -2,15 +2,17 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class RedirectToRouteResultExecutor + public class RedirectToRouteResultExecutor : IActionResultExecutor { private readonly ILogger _logger; private readonly IUrlHelperFactory _urlHelperFactory; @@ -31,7 +33,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal _urlHelperFactory = urlHelperFactory; } - public void Execute(ActionContext context, RedirectToRouteResult result) + /// + public virtual Task ExecuteAsync(ActionContext context, RedirectToRouteResult result) { var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context); @@ -58,6 +61,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal { context.HttpContext.Response.Redirect(destinationUrl, result.Permanent); } + + return Task.CompletedTask; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/VirtualFileResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/VirtualFileResultExecutor.cs similarity index 97% rename from src/Microsoft.AspNetCore.Mvc.Core/Internal/VirtualFileResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/VirtualFileResultExecutor.cs index 825de2686d..694b58e84a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/VirtualFileResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/VirtualFileResultExecutor.cs @@ -12,9 +12,9 @@ using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class VirtualFileResultExecutor : FileResultExecutorBase + public class VirtualFileResultExecutor : FileResultExecutorBase , IActionResultExecutor { private readonly IHostingEnvironment _hostingEnvironment; @@ -29,6 +29,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _hostingEnvironment = hostingEnvironment; } + /// public virtual Task ExecuteAsync(ActionContext context, VirtualFileResult result) { if (context == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs index 341028ae5e..ca20eb5020 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs @@ -2,9 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 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.Routing; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc { @@ -89,6 +95,19 @@ namespace Microsoft.AspNetCore.Mvc public IUrlHelper UrlHelper { get; set; } /// + public override Task ExecuteResultAsync(ActionContext context) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var executor = context.HttpContext.RequestServices.GetRequiredService>(); + 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) { if (context == null) @@ -96,8 +115,32 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); - executor.Execute(context, this); + var services = context.HttpContext.RequestServices; + var urlHelperFactory = services.GetRequiredService(); + var logger = services.GetRequiredService>(); + + 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 } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ObjectResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/ObjectResult.cs index a1718ace00..1148ceffc1 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ObjectResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ObjectResult.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; @@ -33,10 +34,8 @@ namespace Microsoft.AspNetCore.Mvc public override Task ExecuteResultAsync(ActionContext context) { - var executor = context.HttpContext.RequestServices.GetRequiredService(); - var result = executor.ExecuteAsync(context, this); - - return result; + var executor = context.HttpContext.RequestServices.GetRequiredService>(); + return executor.ExecuteAsync(context, this); } /// diff --git a/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs index a0be57ab17..c83dc1442a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Net.Http.Headers; @@ -74,7 +75,7 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); + var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs index 2074513d50..6aae329d12 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs @@ -2,10 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 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.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc { @@ -99,6 +105,19 @@ namespace Microsoft.AspNetCore.Mvc public IUrlHelper UrlHelper { get; set; } /// + public override Task ExecuteResultAsync(ActionContext context) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var executor = context.HttpContext.RequestServices.GetRequiredService>(); + 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) { if (context == null) @@ -106,8 +125,32 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); - executor.Execute(context, this); + var services = context.HttpContext.RequestServices; + var urlHelperFactory = services.GetRequiredService(); + var logger = services.GetRequiredService>(); + + 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 } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs index 562184432d..7e48ac38c3 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs @@ -2,10 +2,17 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 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.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc { @@ -165,6 +172,19 @@ namespace Microsoft.AspNetCore.Mvc public string Fragment { get; set; } /// + public override Task ExecuteResultAsync(ActionContext context) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var executor = context.HttpContext.RequestServices.GetRequiredService>(); + 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) { if (context == null) @@ -172,8 +192,37 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); - executor.Execute(context, this); + var services = context.HttpContext.RequestServices; + var urlHelperFactory = services.GetRequiredService(); + var logger = services.GetRequiredService>(); + + 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 } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs index 0750e2754e..38740594ec 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; @@ -204,15 +206,15 @@ namespace Microsoft.AspNetCore.Mvc public string Host { get; set; } /// - public override void ExecuteResult(ActionContext context) + public override Task ExecuteResultAsync(ActionContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); - executor.Execute(context, this); + var executor = context.HttpContext.RequestServices.GetRequiredService>(); + return executor.ExecuteAsync(context, this); } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs index e7401bdabf..500d8f3d2f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs @@ -2,10 +2,17 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 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.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc { @@ -157,6 +164,19 @@ namespace Microsoft.AspNetCore.Mvc public string Fragment { get; set; } /// + public override Task ExecuteResultAsync(ActionContext context) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var executor = context.HttpContext.RequestServices.GetRequiredService>(); + 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) { if (context == null) @@ -164,8 +184,36 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); - executor.Execute(context, this); + var services = context.HttpContext.RequestServices; + var urlHelperFactory = services.GetRequiredService(); + var logger = services.GetRequiredService>(); + + 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 } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/VirtualFileResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/VirtualFileResult.cs index 467d2d709f..2e37c94a89 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/VirtualFileResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/VirtualFileResult.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; @@ -84,7 +85,7 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var executor = context.HttpContext.RequestServices.GetRequiredService(); + var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs index 179c77b697..7e7ce79fb2 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; @@ -148,8 +149,8 @@ namespace Microsoft.Extensions.DependencyInjection // View Engine and related infrastructure // services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); + services.TryAddSingleton, ViewResultExecutor>(); + services.TryAddSingleton, PartialViewResultExecutor>(); // Support for activating ViewDataDictionary services.TryAddEnumerable( @@ -188,7 +189,7 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddSingleton< IViewComponentDescriptorCollectionProvider, DefaultViewComponentDescriptorCollectionProvider>(); - services.TryAddSingleton(); + services.TryAddSingleton, ViewComponentResultExecutor>(); services.TryAddSingleton(); services.TryAddTransient(); diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/PartialViewResult.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/PartialViewResult.cs index 1f50b436a6..64a8c5fcbb 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/PartialViewResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/PartialViewResult.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ViewEngines; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; @@ -57,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc public string ContentType { get; set; } /// - public override async Task ExecuteResultAsync(ActionContext context) + public override Task ExecuteResultAsync(ActionContext context) { if (context == null) { @@ -65,16 +66,8 @@ namespace Microsoft.AspNetCore.Mvc } var services = context.HttpContext.RequestServices; - var executor = services.GetRequiredService(); - - var result = executor.FindView(context, this); - result.EnsureSuccessful(originalLocations: null); - - var view = result.View; - using (view as IDisposable) - { - await executor.ExecuteAsync(context, view, this); - } + var executor = services.GetRequiredService>(); + return executor.ExecuteAsync(context, this); } } } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewComponentResult.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewComponentResult.cs index 0a500a0276..898f676067 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewComponentResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewComponentResult.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; using Microsoft.Extensions.DependencyInjection; @@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc } var services = context.HttpContext.RequestServices; - var executor = services.GetRequiredService(); + var executor = services.GetRequiredService>(); return executor.ExecuteAsync(context, this); } } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/PartialViewResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs similarity index 88% rename from src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/PartialViewResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs index 369d4d84e9..f0c178eaf4 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/PartialViewResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs @@ -6,18 +6,20 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ViewEngines; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal +namespace Microsoft.AspNetCore.Mvc.ViewFeatures { /// /// Finds and executes an for a . /// - public class PartialViewResultExecutor : ViewExecutor + public class PartialViewResultExecutor : ViewExecutor, IActionResultExecutor { private const string ActionNameKey = "action"; @@ -162,6 +164,29 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal viewResult.StatusCode); } + /// + 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) { if (context == null) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewComponentResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewComponentResultExecutor.cs similarity index 86% rename from src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewComponentResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewComponentResultExecutor.cs index 19a8ba4bd3..1ae46c44b0 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewComponentResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewComponentResultExecutor.cs @@ -2,21 +2,22 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Text; using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal +namespace Microsoft.AspNetCore.Mvc.ViewFeatures { - public class ViewComponentResultExecutor + public class ViewComponentResultExecutor : IActionResultExecutor { private readonly HtmlEncoder _htmlEncoder; private readonly HtmlHelperOptions _htmlHelperOptions; @@ -63,34 +64,35 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal _tempDataDictionaryFactory = tempDataDictionaryFactory; } - public virtual async Task ExecuteAsync(ActionContext context, ViewComponentResult viewComponentResult) + /// + public virtual async Task ExecuteAsync(ActionContext context, ViewComponentResult result) { if (context == null) { 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 viewData = viewComponentResult.ViewData; + var viewData = result.ViewData; if (viewData == null) { viewData = new ViewDataDictionary(_modelMetadataProvider, context.ModelState); } - var tempData = viewComponentResult.TempData; + var tempData = result.TempData; if (tempData == null) { tempData = _tempDataDictionaryFactory.GetTempData(context.HttpContext); } ResponseContentTypeHelper.ResolveContentTypeAndEncoding( - viewComponentResult.ContentType, + result.ContentType, response.ContentType, ViewExecutor.DefaultContentType, out var resolvedContentType, @@ -98,9 +100,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal 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)) @@ -117,9 +119,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal var viewComponentHelper = context.HttpContext.RequestServices.GetRequiredService(); (viewComponentHelper as IViewContextAware)?.Contextualize(viewContext); - var result = await GetViewComponentResult(viewComponentHelper, _logger, viewComponentResult); - - result.WriteTo(writer, _htmlEncoder); + var viewComponentResult = await GetViewComponentResult(viewComponentHelper, _logger, result); + viewComponentResult.WriteTo(writer, _htmlEncoder); } } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs similarity index 84% rename from src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs rename to src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs index 4b4badc60f..aa60b7f3d9 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs @@ -6,18 +6,20 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ViewEngines; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal +namespace Microsoft.AspNetCore.Mvc.ViewFeatures { /// /// Finds and executes an for a . /// - public class ViewResultExecutor : ViewExecutor + public class ViewResultExecutor : ViewExecutor, IActionResultExecutor { private const string ActionNameKey = "action"; @@ -141,39 +143,35 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal return result; } - /// - /// Executes the asynchronously. - /// - /// The associated with the current request. - /// The . - /// The . - /// A which will complete when view execution is completed. - public virtual Task ExecuteAsync(ActionContext actionContext, IView view, ViewResult viewResult) + /// + public async Task ExecuteAsync(ActionContext context, ViewResult result) { - 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) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs index bc43a62247..b169604d14 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ViewEngines; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; @@ -64,17 +65,8 @@ namespace Microsoft.AspNetCore.Mvc throw new ArgumentNullException(nameof(context)); } - var services = context.HttpContext.RequestServices; - var executor = services.GetRequiredService(); - - var result = executor.FindView(context, this); - result.EnsureSuccessful(originalLocations: null); - - var view = result.View; - using (view as IDisposable) - { - await executor.ExecuteAsync(context, view, this); - } + var executor = context.HttpContext.RequestServices.GetRequiredService>(); + await executor.ExecuteAsync(context, this); } } } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtActionResultTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtActionResultTests.cs index b6c5125680..8acea5b62a 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtActionResultTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtActionResultTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; @@ -273,7 +274,7 @@ namespace Microsoft.AspNetCore.Mvc var options = new TestOptionsManager(); options.Value.OutputFormatters.Add(formatter.Object); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtRouteResultTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtRouteResultTests.cs index c558746221..679f4190e2 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtRouteResultTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedAtRouteResultTests.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Testing; @@ -182,7 +183,7 @@ namespace Microsoft.AspNetCore.Mvc var options = new TestOptionsManager(); options.Value.OutputFormatters.Add(formatter.Object); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedResultTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedResultTests.cs index d0020001af..a1a33adaad 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedResultTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/AcceptedResultTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; @@ -138,7 +139,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test var options = new TestOptionsManager(); options.Value.OutputFormatters.Add(formatter.Object); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ContentResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ContentResultTest.cs index 376e5bc8f2..a9e878cc8f 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ContentResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ContentResultTest.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.TestCommon; using Microsoft.AspNetCore.Mvc.ViewComponents; @@ -269,7 +270,7 @@ namespace Microsoft.AspNetCore.Mvc .Returns(new char[DefaultCharacterChunkSize]); var services = new ServiceCollection(); - services.AddSingleton(new ContentResultExecutor( + services.AddSingleton>(new ContentResultExecutor( new Logger(NullLoggerFactory.Instance), new MemoryPoolHttpResponseStreamWriterFactory(ArrayPool.Shared, charArrayPool.Object))); return services; diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtActionResultTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtActionResultTests.cs index 66663dcddc..e9bbab4e60 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtActionResultTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtActionResultTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Mvc ArrayPool.Shared)); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtRouteResultTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtRouteResultTests.cs index 255536e0f4..d313641f6b 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtRouteResultTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedAtRouteResultTests.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Testing; @@ -110,7 +111,7 @@ namespace Microsoft.AspNetCore.Mvc ArrayPool.Shared)); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedResultTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedResultTests.cs index 3b9c0c22e1..5e8c314bb3 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedResultTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/CreatedResultTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Mvc ArrayPool.Shared)); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileContentResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileContentResultTest.cs index 64977aaee5..7dcad93cf8 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileContentResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileContentResultTest.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.TestCommon; using Microsoft.AspNetCore.Routing; @@ -422,7 +423,7 @@ namespace Microsoft.AspNetCore.Mvc private static IServiceCollection CreateServices() { var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton, FileContentResultExecutor>(); services.AddSingleton(NullLoggerFactory.Instance); return services; diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs index a16d207956..a520b04c38 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileStreamResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileStreamResultTest.cs index e4b342b782..1b22e31cf9 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileStreamResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileStreamResultTest.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.TestCommon; using Microsoft.AspNetCore.Routing; @@ -527,7 +528,7 @@ namespace Microsoft.AspNetCore.Mvc private static IServiceCollection CreateServices() { var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton, FileStreamResultExecutor>(); services.AddSingleton(NullLoggerFactory.Instance); return services; } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/HttpNotFoundObjectResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/HttpNotFoundObjectResultTest.cs index 86ea08d404..4f8449231b 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/HttpNotFoundObjectResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/HttpNotFoundObjectResultTest.cs @@ -7,6 +7,7 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; @@ -75,7 +76,7 @@ namespace Microsoft.AspNetCore.Mvc ArrayPool.Shared)); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/HttpOkObjectResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/HttpOkObjectResultTest.cs index f587df3379..2c701e9e74 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/HttpOkObjectResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/HttpOkObjectResultTest.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; @@ -76,7 +77,7 @@ namespace Microsoft.AspNetCore.Mvc ArrayPool.Shared)); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Infrastructure/ObjectResultExecutorTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Infrastructure/ObjectResultExecutorTest.cs index e7482d404f..fa2dff80a4 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Infrastructure/ObjectResultExecutorTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Infrastructure/ObjectResultExecutorTest.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.TestCommon; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -16,7 +17,7 @@ using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; using Xunit; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { public class ObjectResultExecutorTest { diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionInvokerTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionInvokerTest.cs index 1aae7a099d..f1cc759921 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionInvokerTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionInvokerTest.cs @@ -1602,7 +1602,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var services = new ServiceCollection(); services.AddSingleton(NullLoggerFactory.Instance); services.AddSingleton>(mvcOptionsAccessor); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( mvcOptionsAccessor, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/LocalRedirectResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/LocalRedirectResultTest.cs index 0409d15052..f12ae0e51d 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/LocalRedirectResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/LocalRedirectResultTest.cs @@ -2,9 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; @@ -63,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc } [Fact] - public void Execute_ReturnsExpectedValues() + public async Task Execute_ReturnsExpectedValues() { // Arrange var appRoot = "/"; @@ -78,7 +80,7 @@ namespace Microsoft.AspNetCore.Mvc var result = new LocalRedirectResult(contentPath); // Act - result.ExecuteResult(actionContext); + await result.ExecuteResultAsync(actionContext); // Assert httpResponse.Verify(); @@ -87,7 +89,7 @@ namespace Microsoft.AspNetCore.Mvc [Theory] [InlineData("", "Home/About", "/Home/About")] [InlineData("/myapproot", "http://www.example.com", "/test")] - public void Execute_Throws_ForNonLocalUrl( + public async Task Execute_Throws_ForNonLocalUrl( string appRoot, string contentPath, string expectedPath) @@ -102,7 +104,7 @@ namespace Microsoft.AspNetCore.Mvc var result = new LocalRedirectResult(contentPath); // Act & Assert - var exception = Assert.Throws(() => result.ExecuteResult(actionContext)); + var exception = await Assert.ThrowsAsync(() => result.ExecuteResultAsync(actionContext)); Assert.Equal( "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.", @@ -120,7 +122,7 @@ namespace Microsoft.AspNetCore.Mvc private static IServiceProvider GetServiceProvider() { var serviceCollection = new ServiceCollection(); - serviceCollection.AddSingleton(); + serviceCollection.AddSingleton, LocalRedirectResultExecutor>(); serviceCollection.AddSingleton(); serviceCollection.AddTransient(); return serviceCollection.BuildServiceProvider(); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ObjectResultTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ObjectResultTests.cs index 4a4f4dfcd5..acc9a2c19d 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ObjectResultTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ObjectResultTests.cs @@ -5,6 +5,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -63,7 +64,7 @@ namespace Microsoft.AspNetCore.Mvc private static IServiceProvider CreateServices() { var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( new TestOptionsManager(), new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/PhysicalFileResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/PhysicalFileResultTest.cs index 77e82bf686..523996880d 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/PhysicalFileResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/PhysicalFileResultTest.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.TestCommon; using Microsoft.AspNetCore.Routing; diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectResultTest.cs index be398a6235..dc37c52ae7 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectResultTest.cs @@ -2,9 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; @@ -65,7 +67,7 @@ namespace Microsoft.AspNetCore.Mvc [Theory] [InlineData("", "/Home/About", "/Home/About")] [InlineData("/myapproot", "/test", "/test")] - public void Execute_ReturnsContentPath_WhenItDoesNotStartWithTilde( + public async Task Execute_ReturnsContentPath_WhenItDoesNotStartWithTilde( string appRoot, string contentPath, string expectedPath) @@ -80,7 +82,7 @@ namespace Microsoft.AspNetCore.Mvc var result = new RedirectResult(contentPath); // Act - result.ExecuteResult(actionContext); + await result.ExecuteResultAsync(actionContext); // Assert // Verifying if Redirect was called with the specific Url and parameter flag. @@ -93,7 +95,7 @@ namespace Microsoft.AspNetCore.Mvc [InlineData("/", "~/", "/")] [InlineData("", "~/Home/About", "/Home/About")] [InlineData("/myapproot", "~/", "/myapproot/")] - public void Execute_ReturnsAppRelativePath_WhenItStartsWithTilde( + public async Task Execute_ReturnsAppRelativePath_WhenItStartsWithTilde( string appRoot, string contentPath, string expectedPath) @@ -108,7 +110,7 @@ namespace Microsoft.AspNetCore.Mvc var result = new RedirectResult(contentPath); // Act - result.ExecuteResult(actionContext); + await result.ExecuteResultAsync(actionContext); // Assert // Verifying if Redirect was called with the specific Url and parameter flag. @@ -128,7 +130,7 @@ namespace Microsoft.AspNetCore.Mvc private static IServiceProvider GetServiceProvider() { var serviceCollection = new ServiceCollection(); - serviceCollection.AddSingleton(); + serviceCollection.AddSingleton, RedirectResultExecutor>(); serviceCollection.AddSingleton(); serviceCollection.AddTransient(); return serviceCollection.BuildServiceProvider(); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToActionResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToActionResultTest.cs index ee9045ffe1..28a5976c9b 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToActionResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToActionResultTest.cs @@ -5,6 +5,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; @@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.Mvc private static IServiceCollection CreateServices() { var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton, RedirectToActionResultExecutor>(); services.AddSingleton(); services.AddSingleton(NullLoggerFactory.Instance); return services; diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToPageResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToPageResultTest.cs index 6b98f0086f..40026e2130 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToPageResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToPageResultTest.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Routing; @@ -297,7 +298,7 @@ namespace Microsoft.AspNetCore.Mvc private static IServiceProvider CreateServices(IUrlHelperFactory factory = null) { var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton, RedirectToPageResultExecutor>(); if (factory != null) { diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToRouteResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToRouteResultTest.cs index 0b03b3efe6..6b0de7b699 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToRouteResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/RedirectToRouteResultTest.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; @@ -179,7 +180,7 @@ namespace Microsoft.AspNetCore.Mvc private static IServiceCollection CreateServices(IUrlHelperFactory factory = null) { var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton, RedirectToRouteResultExecutor>(); if (factory != null) { diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/VirtualFileResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/VirtualFileResultTest.cs index 07b5f7e72c..418b9a7f49 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/VirtualFileResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/VirtualFileResultTest.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.TestCommon; using Microsoft.AspNetCore.Routing; @@ -73,7 +74,7 @@ namespace Microsoft.AspNetCore.Mvc httpContext.Response.Body = new MemoryStream(); httpContext.RequestServices = new ServiceCollection() .AddSingleton(appEnvironment.Object) - .AddTransient() + .AddTransient, TestVirtualFileResultExecutor>() .AddTransient() .BuildServiceProvider(); @@ -117,7 +118,7 @@ namespace Microsoft.AspNetCore.Mvc httpContext.Response.Body = new MemoryStream(); httpContext.RequestServices = new ServiceCollection() .AddSingleton(appEnvironment.Object) - .AddTransient() + .AddTransient, TestVirtualFileResultExecutor>() .AddTransient() .BuildServiceProvider(); @@ -162,7 +163,7 @@ namespace Microsoft.AspNetCore.Mvc httpContext.Response.Body = new MemoryStream(); httpContext.RequestServices = new ServiceCollection() .AddSingleton(appEnvironment.Object) - .AddTransient() + .AddTransient, TestVirtualFileResultExecutor>() .AddTransient() .BuildServiceProvider(); @@ -207,7 +208,7 @@ namespace Microsoft.AspNetCore.Mvc httpContext.Response.Body = new MemoryStream(); httpContext.RequestServices = new ServiceCollection() .AddSingleton(appEnvironment.Object) - .AddTransient() + .AddTransient, TestVirtualFileResultExecutor>() .AddTransient() .BuildServiceProvider(); @@ -250,7 +251,7 @@ namespace Microsoft.AspNetCore.Mvc httpContext.Response.Body = new MemoryStream(); httpContext.RequestServices = new ServiceCollection() .AddSingleton(appEnvironment.Object) - .AddTransient() + .AddTransient, TestVirtualFileResultExecutor>() .AddTransient() .BuildServiceProvider(); @@ -292,7 +293,7 @@ namespace Microsoft.AspNetCore.Mvc httpContext.Response.Body = new MemoryStream(); httpContext.RequestServices = new ServiceCollection() .AddSingleton(appEnvironment.Object) - .AddTransient() + .AddTransient, TestVirtualFileResultExecutor>() .AddTransient() .BuildServiceProvider(); @@ -334,7 +335,7 @@ namespace Microsoft.AspNetCore.Mvc httpContext.Response.Body = new MemoryStream(); httpContext.RequestServices = new ServiceCollection() .AddSingleton(appEnvironment.Object) - .AddTransient() + .AddTransient, TestVirtualFileResultExecutor>() .AddTransient() .BuildServiceProvider(); @@ -376,7 +377,7 @@ namespace Microsoft.AspNetCore.Mvc httpContext.Response.Body = new MemoryStream(); httpContext.RequestServices = new ServiceCollection() .AddSingleton(appEnvironment.Object) - .AddTransient() + .AddTransient, TestVirtualFileResultExecutor>() .AddTransient() .BuildServiceProvider(); var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); @@ -464,7 +465,7 @@ namespace Microsoft.AspNetCore.Mvc .Returns(GetFileProvider(path)); httpContext.RequestServices = new ServiceCollection() .AddSingleton(appEnvironment.Object) - .AddTransient() + .AddTransient, TestVirtualFileResultExecutor>() .AddTransient() .BuildServiceProvider(); @@ -665,7 +666,12 @@ namespace Microsoft.AspNetCore.Mvc var hostingEnvironment = new Mock(); - services.AddSingleton(executorType ?? typeof(TestVirtualFileResultExecutor)); + services.AddSingleton, TestVirtualFileResultExecutor>(); + if (executorType != null) + { + services.AddSingleton(typeof(IActionResultExecutor), executorType); + } + services.AddSingleton(hostingEnvironment.Object); services.AddSingleton(NullLoggerFactory.Instance); @@ -708,7 +714,7 @@ namespace Microsoft.AspNetCore.Mvc public override Task ExecuteResultAsync(ActionContext context) { - var executor = context.HttpContext.RequestServices.GetRequiredService(); + var executor = (TestVirtualFileResultExecutor)context.HttpContext.RequestServices.GetRequiredService>(); executor.IsAscii = IsAscii; return executor.ExecuteAsync(context, this); } diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/PartialViewResultTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/PartialViewResultTest.cs index 95be95bb99..bca76d7e4d 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/PartialViewResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/PartialViewResultTest.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewEngines; @@ -226,7 +227,7 @@ namespace Microsoft.AspNetCore.Mvc new EmptyModelMetadataProvider()); var services = new ServiceCollection(); - services.AddSingleton(viewExecutor); + services.AddSingleton>(viewExecutor); var httpContext = new DefaultHttpContext(); httpContext.RequestServices = services.BuildServiceProvider(); diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewComponentResultTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewComponentResultTest.cs index f7da43fc3b..79d6fbb91f 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewComponentResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewComponentResultTest.cs @@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.TestCommon; using Microsoft.AspNetCore.Mvc.ViewComponents; @@ -579,7 +580,7 @@ namespace Microsoft.AspNetCore.Mvc services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton, ViewComponentResultExecutor>(); return services; } diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/PartialViewResultExecutorTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs similarity index 99% rename from test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/PartialViewResultExecutorTest.cs rename to test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs index c8976cb813..7b9ee86763 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/PartialViewResultExecutorTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.ModelBinding; @@ -16,7 +15,7 @@ using Microsoft.Net.Http.Headers; using Moq; using Xunit; -namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal +namespace Microsoft.AspNetCore.Mvc.ViewFeatures { public class PartialViewResultExecutorTest { diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ViewResultExecutorTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs similarity index 98% rename from test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ViewResultExecutorTest.cs rename to test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs index 36ffc6b25f..487368558c 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ViewResultExecutorTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ViewEngines; @@ -15,7 +14,7 @@ using Microsoft.Net.Http.Headers; using Moq; using Xunit; -namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal +namespace Microsoft.AspNetCore.Mvc.ViewFeatures { public class ViewResultExecutorTest { @@ -268,7 +267,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal }; // Act - await executor.ExecuteAsync(context, Mock.Of(), viewResult); + await executor.ExecuteAsync(context, viewResult); // Assert Assert.Equal("application/x-my-content-type", context.HttpContext.Response.ContentType); @@ -292,7 +291,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal }; // Act - await executor.ExecuteAsync(context, Mock.Of(), viewResult); + await executor.ExecuteAsync(context, viewResult); // Assert Assert.Equal(404, context.HttpContext.Response.StatusCode); diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewResultTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewResultTest.cs index 374cb87301..814a1c7300 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewResultTest.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewEngines; @@ -238,7 +239,7 @@ namespace Microsoft.AspNetCore.Mvc new EmptyModelMetadataProvider()); var services = new ServiceCollection(); - services.AddSingleton(viewExecutor); + services.AddSingleton>(viewExecutor); var httpContext = new DefaultHttpContext(); httpContext.RequestServices = services.BuildServiceProvider(); diff --git a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/BadRequestErrorMessageResultTest.cs b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/BadRequestErrorMessageResultTest.cs index d341e9e270..e2486da5e1 100644 --- a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/BadRequestErrorMessageResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/BadRequestErrorMessageResultTest.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; @@ -74,7 +75,7 @@ namespace System.Web.Http ArrayPool.Shared)); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ExceptionResultTest.cs b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ExceptionResultTest.cs index 806b0311b7..659028ca80 100644 --- a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ExceptionResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ExceptionResultTest.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; @@ -74,7 +75,7 @@ namespace System.Web.Http ArrayPool.Shared)); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/InvalidModelStateResultTest.cs b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/InvalidModelStateResultTest.cs index 1c5b225484..58b775b3f3 100644 --- a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/InvalidModelStateResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/InvalidModelStateResultTest.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Routing; @@ -87,7 +88,7 @@ namespace System.Web.Http ArrayPool.Shared)); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance)); diff --git a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/NegotiatedContentResultTest.cs b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/NegotiatedContentResultTest.cs index 307f798a24..a15c9c2f3a 100644 --- a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/NegotiatedContentResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/NegotiatedContentResultTest.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; @@ -75,7 +76,7 @@ namespace System.Web.Http ArrayPool.Shared)); var services = new ServiceCollection(); - services.AddSingleton(new ObjectResultExecutor( + services.AddSingleton>(new ObjectResultExecutor( options, new TestHttpResponseStreamWriterFactory(), NullLoggerFactory.Instance));