我正在遵循 ninject 过滤器属性设置page.
对于他们来说,他们有:
.WithConstructorArgumentFromControllerAttribute<LogAttribute>(
"logLevel", attribute => attribute.LogLevel);
第二个参数需要一个Func<LogAttribute, object> callback
。他们的实际参数列表设置如下:
Log(LogLevel = Level.Debug)
但我的过滤器属性设置如下:
public class AuthAttribute : FilterAttribute { }
public class AuthFilter : IAuthorizationFilter
{
private readonly IUserService userService;
private string[] roles;
//Stuck on the constructor also. How do I accept params?
public AuthFilter(IUserService userService, params string[] roles)
{
this.userService = userService;
this.roles = roles;
}
public void OnAuthorization(AuthorizationContext filterContext)
{
throw new NotImplementedException();
}
}
不知怎的,这是错误的。因为我希望我的过滤器看起来像:
[Auth("Admin", "Contrib")]
我的绑定:
kernel.BindFilter<AuthFilter>(FilterScope.Controller, 0)
.WhenControllerHas<AuthAttribute>()
.WithConstructorArgumentFromControllerAttribute<AuthAttribute>("roles", /*Stuck here*/)