using Microsoft.AspNetCore.Mvc.ApplicationModels; using System; using System.Reflection; namespace Infrastructure.Web.Mvc { public class GenericControllerRouteConvention : IControllerModelConvention { public void Apply(ControllerModel controller) { if (controller is null) { throw new ArgumentNullException(nameof(controller)); } if (controller.ControllerType.IsGenericType) { var genericType = controller.ControllerType.GenericTypeArguments[0]; var customNameAttribute = genericType.GetCustomAttribute(); if (customNameAttribute != null) { controller.ControllerName = genericType.Name; //controller.Selectors.Add(new SelectorModel //{ // AttributeRouteModel = new AttributeRouteModel(new RouteAttribute(customNameAttribute.Route ?? $"Entity/[controller]/[action]")), //}); } } } } }