From db6755a5bb191f9d80ef3f3f1b785bf06e40b4ef Mon Sep 17 00:00:00 2001 From: Kieron McIntyre Date: Fri, 23 Oct 2015 10:04:14 +0100 Subject: [PATCH] Addition of allowance for async/await Index actions --- src/Umbraco.Web/Mvc/RenderActionInvoker.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web/Mvc/RenderActionInvoker.cs b/src/Umbraco.Web/Mvc/RenderActionInvoker.cs index f6b3c673bf..b846b23be6 100644 --- a/src/Umbraco.Web/Mvc/RenderActionInvoker.cs +++ b/src/Umbraco.Web/Mvc/RenderActionInvoker.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Linq; +using System.Threading.Tasks; using System.Web.Mvc; using System.Web.Mvc.Async; @@ -12,7 +13,7 @@ namespace Umbraco.Web.Mvc public class RenderActionInvoker : AsyncControllerActionInvoker { - private static readonly ConcurrentDictionary IndexDescriptors = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary IndexDescriptors = new ConcurrentDictionary(); /// /// Ensures that if an action for the Template name is not explicitly defined by a user, that the 'Index' action will execute @@ -31,16 +32,15 @@ namespace Umbraco.Web.Mvc //check if the controller is an instance of IRenderMvcController if (controllerContext.Controller is IRenderMvcController) { - return IndexDescriptors.GetOrAdd(controllerContext.Controller.GetType(), - type => new ReflectedActionDescriptor( - controllerContext.Controller.GetType().GetMethods() - .First(x => x.Name == "Index" && - x.GetCustomAttributes(typeof (NonActionAttribute), false).Any() == false), - "Index", - controllerDescriptor)); - + var methodInfo = controllerContext.Controller.GetType().GetMethods() + .First(x => x.Name == "Index" && + x.GetCustomAttributes(typeof (NonActionAttribute), false).Any() == false); + ad = typeof (Task).IsAssignableFrom(methodInfo.ReturnType) + ? new TaskAsyncActionDescriptor(methodInfo, "Index", controllerDescriptor) + : (ActionDescriptor) new ReflectedActionDescriptor(methodInfo, "Index", controllerDescriptor); + return IndexDescriptors.GetOrAdd(controllerContext.Controller.GetType(), type => ad); } } return ad;