ISimApiAuthChecker 改为按接口注册 + getAll<T>() 解析,移除 SimApiOptions.authCheckers 手动列表
This commit is contained in:
@@ -39,6 +39,7 @@ import simapi.communications.*
|
||||
import simapi.configurations.*
|
||||
import simapi.controllers.*
|
||||
import simapi.helpers.*
|
||||
import simapi.interfaces.*
|
||||
import simapi.logger.*
|
||||
import simapi.middlewares.*
|
||||
|
||||
@@ -283,14 +284,13 @@ public class SimApiExtensions {
|
||||
builder.services.addSingleton<SimApiAuth, SimApiAuth>()
|
||||
}
|
||||
|
||||
// ISimApiAuthChecker 自动扫描注册(对齐 C# AddSimApi 中遍历调用者程序集 AddScoped 注册 checker)
|
||||
// 扫描调用者包中的 ISimApiAuthChecker 实现类:填充 options.authCheckers(供 @SimApiAuth 执行时解析)
|
||||
// 并注册到 DI(按实现类类型注册,供 getOrThrow(checkerType) 解析)
|
||||
// ISimApiAuthChecker 自动扫描注册(对齐 C# AddSimApi 中遍历调用者程序集 AddScoped(ISimApiAuthChecker, type))
|
||||
// 扫描调用者包中的实现类,按【接口】注册;执行时用 getAll<ISimApiAuthChecker>() 一次解析全部实现,
|
||||
// 无需在 SimApiOptions 里维护类型列表。
|
||||
if (options.enableSimApiAuth) {
|
||||
let checkers = SimApiControllerScanner.scanAuthCheckers()
|
||||
for (checkerType in checkers) {
|
||||
options.authCheckers.add(checkerType)
|
||||
builder.services.addScoped(checkerType)
|
||||
builder.services.addScoped(TypeInfo.of<ISimApiAuthChecker>(), checkerType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user