Skip to content

Commit

Permalink
😊 修复 动态 WebAPI 不支持贴有 [NonController] 特性的控制器
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkSoul committed Dec 10, 2024
1 parent 187a178 commit d3fdd24
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ static bool Function(Type type)
// 不能是非公开、基元类型、值类型、抽象类、接口、泛型类
if (!type.IsPublic || type.IsPrimitive || type.IsValueType || type.IsAbstract || type.IsInterface || type.IsGenericType) return false;

// 如果控制器贴有 [NonController] 特性则忽略
if (type.IsDefined(typeof(NonControllerAttribute), false)) return false;

// 继承 ControllerBase 或 实现 IDynamicApiController 的类型 或 贴了 [DynamicApiController] 特性
if ((!typeof(Controller).IsAssignableFrom(type) && typeof(ControllerBase).IsAssignableFrom(type))
|| typeof(IDynamicApiController).IsAssignableFrom(type)
Expand Down
3 changes: 3 additions & 0 deletions framework/Furion/DynamicApiController/Internal/Penetrates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ static bool Function(Type type)
// 不能是非公开、基元类型、值类型、抽象类、接口、泛型类
if (!type.IsPublic || type.IsPrimitive || type.IsValueType || type.IsAbstract || type.IsInterface || type.IsGenericType) return false;

// 如果控制器贴有 [NonController] 特性则忽略
if (type.IsDefined(typeof(NonControllerAttribute), false)) return false;

// 继承 ControllerBase 或 实现 IDynamicApiController 的类型 或 贴了 [DynamicApiController] 特性
if ((!typeof(Controller).IsAssignableFrom(type) && typeof(ControllerBase).IsAssignableFrom(type))
|| typeof(IDynamicApiController).IsAssignableFrom(type)
Expand Down
1 change: 1 addition & 0 deletions samples/Furion.Web.Entry/Controllers/TestApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Furion.Web.Entry.Controllers;
/// </summary>
[Route("api/[controller]")]
[ApiController]
//[NonController]
public class TestApiController : ControllerBase
{
[HttpGet, NonUnify]
Expand Down

0 comments on commit d3fdd24

Please sign in to comment.