using Microsoft.AspNetCore.Mvc.Controllers; using System.Reflection; namespace Ds.Module.DynamicApi { /// /// /// public class AutoAPIControllerFeatureProvider : ControllerFeatureProvider { //IApplicationFeatureProvider, IApplicationFeatureProvider //{ //public void PopulateFeature(IEnumerable parts, ControllerFeature feature) //{ // foreach (var part in parts.OfType()) // { // foreach (var type in part.Types) // { // if (IsController(type) && !feature.Controllers.Contains(type)) // { // feature.Controllers.Add(type); // } // } // } //} //protected override bool IsController(TypeInfo typeInfo) protected override bool IsController(TypeInfo typeInfo) { //判断是否继承了指定的接口 if (typeof(IDsAutoAPIServices).IsAssignableFrom(typeInfo)) { if (!typeInfo.IsInterface && !typeInfo.IsAbstract && !typeInfo.IsGenericType && typeInfo.IsPublic) { return true; } } return false; //return base.IsController(typeInfo); } } }