/// <summary> /// 参考代码Microsoft.AspNetCore.Mvc.Internal.AuthorizationApplicationModelProvider /// </summary> public class TestApplicationModelProvider : IApplicationModelProvider { public void OnProvidersExecuting(ApplicationModelProviderContext context) { //获取控制器上指定类型的属性 var ad = context.Result.Controllers.First().Attributes.OfType<IAuthorizeData>(); } public void OnProvidersExecuted(ApplicationModelProviderContext context) { } public int Order { get; } = -1000 + 10; }
注册:services.AddTransient<IApplicationModelProvider, TestApplicationModelProvider>();