Addition of allowance for async/await Index actions

This commit is contained in:
Kieron McIntyre
2015-10-23 10:04:14 +01:00
parent 017663833a
commit db6755a5bb

View File

@@ -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<Type, ReflectedActionDescriptor> IndexDescriptors = new ConcurrentDictionary<Type, ReflectedActionDescriptor>();
private static readonly ConcurrentDictionary<Type, ActionDescriptor> IndexDescriptors = new ConcurrentDictionary<Type, ActionDescriptor>();
/// <summary>
/// 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;