Remove ControllerDescriptor and fix ControllerActionDescriptor to pick the right type for the display name.
This commit is contained in:
parent
de50d3dbf9
commit
2eef4dd3cf
|
|
@ -10,27 +10,21 @@ namespace Microsoft.AspNet.Mvc
|
||||||
[DebuggerDisplay("CA {DisplayName}(RC-{RouteConstraints.Count})")]
|
[DebuggerDisplay("CA {DisplayName}(RC-{RouteConstraints.Count})")]
|
||||||
public class ControllerActionDescriptor : ActionDescriptor
|
public class ControllerActionDescriptor : ActionDescriptor
|
||||||
{
|
{
|
||||||
public string ControllerName
|
public string ControllerName { get; set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return ControllerDescriptor.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodInfo MethodInfo { get; set; }
|
public MethodInfo MethodInfo { get; set; }
|
||||||
|
|
||||||
public ControllerDescriptor ControllerDescriptor { get; set; }
|
public TypeInfo ControllerTypeInfo { get; set; }
|
||||||
|
|
||||||
public override string DisplayName
|
public override string DisplayName
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (base.DisplayName == null && MethodInfo != null)
|
if (base.DisplayName == null && ControllerTypeInfo != null && MethodInfo != null)
|
||||||
{
|
{
|
||||||
base.DisplayName = string.Format(
|
base.DisplayName = string.Format(
|
||||||
"{0}.{1}",
|
"{0}.{1}",
|
||||||
MethodInfo.DeclaringType.FullName,
|
ControllerTypeInfo.FullName,
|
||||||
MethodInfo.Name);
|
MethodInfo.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,6 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
foreach (var controller in application.Controllers)
|
foreach (var controller in application.Controllers)
|
||||||
{
|
{
|
||||||
var controllerDescriptor = new ControllerDescriptor()
|
|
||||||
{
|
|
||||||
ControllerTypeInfo = controller.ControllerType,
|
|
||||||
Name = controller.ControllerName,
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (var action in controller.Actions)
|
foreach (var action in controller.Actions)
|
||||||
{
|
{
|
||||||
// Controllers with multiple [Route] attributes (or user defined implementation of
|
// Controllers with multiple [Route] attributes (or user defined implementation of
|
||||||
|
|
@ -58,7 +52,8 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
foreach (var actionDescriptor in actionDescriptors)
|
foreach (var actionDescriptor in actionDescriptors)
|
||||||
{
|
{
|
||||||
actionDescriptor.ControllerDescriptor = controllerDescriptor;
|
actionDescriptor.ControllerName = controller.ControllerName;
|
||||||
|
actionDescriptor.ControllerTypeInfo = controller.ControllerType;
|
||||||
|
|
||||||
AddApiExplorerInfo(actionDescriptor, action, controller);
|
AddApiExplorerInfo(actionDescriptor, action, controller);
|
||||||
AddRouteConstraints(actionDescriptor, controller, action);
|
AddRouteConstraints(actionDescriptor, controller, action);
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
|
||||||
{
|
|
||||||
public class ControllerDescriptor
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public TypeInfo ControllerTypeInfo { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
var controller = _typeActivator.CreateInstance(
|
var controller = _typeActivator.CreateInstance(
|
||||||
_serviceProvider,
|
_serviceProvider,
|
||||||
actionDescriptor.ControllerDescriptor.ControllerTypeInfo.AsType());
|
actionDescriptor.ControllerTypeInfo.AsType());
|
||||||
|
|
||||||
actionContext.Controller = controller;
|
actionContext.Controller = controller;
|
||||||
_controllerActivator.Activate(controller, actionContext);
|
_controllerActivator.Activate(controller, actionContext);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ namespace System.Web.Http
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.ProductsController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.ProductsController).GetTypeInfo();
|
||||||
var actions = results.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType).ToArray();
|
var actions = results.Where(ad => ad.ControllerTypeInfo == controllerType).ToArray();
|
||||||
|
|
||||||
Assert.NotEmpty(actions);
|
Assert.NotEmpty(actions);
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +53,7 @@ namespace System.Web.Http
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.Blog).GetTypeInfo();
|
var controllerType = typeof(TestControllers.Blog).GetTypeInfo();
|
||||||
var actions = results.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType).ToArray();
|
var actions = results.Where(ad => ad.ControllerTypeInfo == controllerType).ToArray();
|
||||||
|
|
||||||
Assert.Empty(actions);
|
Assert.Empty(actions);
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ namespace System.Web.Http
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
||||||
var actions = results
|
var actions = results
|
||||||
.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType)
|
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||||
.Where(ad => ad.MethodInfo.Name == "GetAll")
|
.Where(ad => ad.MethodInfo.Name == "GetAll")
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
|
@ -109,7 +109,7 @@ namespace System.Web.Http
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
||||||
var actions = results
|
var actions = results
|
||||||
.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType)
|
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||||
.Where(ad => ad.MethodInfo.Name == "Edit")
|
.Where(ad => ad.MethodInfo.Name == "Edit")
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ namespace System.Web.Http
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
||||||
var actions = results
|
var actions = results
|
||||||
.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType)
|
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||||
.Where(ad => ad.MethodInfo.Name == "Delete")
|
.Where(ad => ad.MethodInfo.Name == "Delete")
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
|
@ -182,7 +182,7 @@ namespace System.Web.Http
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
||||||
var actions = results
|
var actions = results
|
||||||
.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType)
|
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||||
.Where(ad => ad.MethodInfo.Name == "Options")
|
.Where(ad => ad.MethodInfo.Name == "Options")
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
|
@ -218,7 +218,7 @@ namespace System.Web.Http
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
||||||
var actions = results
|
var actions = results
|
||||||
.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType)
|
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
Assert.NotEmpty(actions);
|
Assert.NotEmpty(actions);
|
||||||
|
|
@ -243,7 +243,7 @@ namespace System.Web.Http
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.StoreController).GetTypeInfo();
|
||||||
var actions = results
|
var actions = results
|
||||||
.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType)
|
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
Assert.NotEmpty(actions);
|
Assert.NotEmpty(actions);
|
||||||
|
|
@ -268,7 +268,7 @@ namespace System.Web.Http
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.EmployeesController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.EmployeesController).GetTypeInfo();
|
||||||
var actions = results
|
var actions = results
|
||||||
.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType)
|
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||||
.Where(ad => ad.Name == "Get")
|
.Where(ad => ad.Name == "Get")
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
|
@ -295,7 +295,7 @@ namespace System.Web.Http
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.EmployeesController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.EmployeesController).GetTypeInfo();
|
||||||
var actions = results
|
var actions = results
|
||||||
.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType)
|
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||||
.Where(ad => ad.Name == "Put")
|
.Where(ad => ad.Name == "Put")
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
|
@ -322,7 +322,7 @@ namespace System.Web.Http
|
||||||
// Assert
|
// Assert
|
||||||
var controllerType = typeof(TestControllers.EmployeesController).GetTypeInfo();
|
var controllerType = typeof(TestControllers.EmployeesController).GetTypeInfo();
|
||||||
var actions = results
|
var actions = results
|
||||||
.Where(ad => ad.ControllerDescriptor.ControllerTypeInfo == controllerType)
|
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||||
.Where(ad => ad.Name == "Post")
|
.Where(ad => ad.Name == "Post")
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ namespace RoutingWebSite
|
||||||
routeValues = new Dictionary<string, object>(_actionContext.RouteData.Values),
|
routeValues = new Dictionary<string, object>(_actionContext.RouteData.Values),
|
||||||
|
|
||||||
action = _actionContext.ActionDescriptor.Name,
|
action = _actionContext.ActionDescriptor.Name,
|
||||||
controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerDescriptor.Name,
|
controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerName,
|
||||||
|
|
||||||
link,
|
link,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ namespace VersioningWebSite
|
||||||
routeValues = new Dictionary<string, object>(_actionContext.RouteData.Values),
|
routeValues = new Dictionary<string, object>(_actionContext.RouteData.Values),
|
||||||
|
|
||||||
action = _actionContext.ActionDescriptor.Name,
|
action = _actionContext.ActionDescriptor.Name,
|
||||||
controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerDescriptor.Name,
|
controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerName,
|
||||||
|
|
||||||
link,
|
link,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue