有没有办法将IOptions传递给自定义IRouteConstraint?我试图检查一个appsetting,看看我是否需要某条路线。
答案 0 :(得分:1)
目前找不到任何参考资料,但
HttpContext
获取,传递给Match
方法示例:
public class MyConstraint : IRouteConstraint
{
public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
{
var options = httpContext.RequestServices.GetService<IOptions<MySettings>>();
return ...;
}
}