You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
977 B
25 lines
977 B
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
|
using System.Reflection;
|
|
|
|
namespace Infrastructure.Web.Mvc
|
|
{
|
|
public class GenericControllerRouteConvention : IControllerModelConvention
|
|
{
|
|
public void Apply(ControllerModel controller)
|
|
{
|
|
if (controller.ControllerType.IsGenericType)
|
|
{
|
|
var genericType = controller.ControllerType.GenericTypeArguments[0];
|
|
var customNameAttribute = genericType.GetCustomAttribute<GeneratedControllerAttribute>();
|
|
if (customNameAttribute != null)
|
|
{
|
|
controller.ControllerName = genericType.Name;
|
|
//controller.Selectors.Add(new SelectorModel
|
|
//{
|
|
// AttributeRouteModel = new AttributeRouteModel(new RouteAttribute(customNameAttribute.Route ?? $"Entity/[controller]/[action]")),
|
|
//});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |