1

有人可以告诉我哪里出错了。我有一个具有以下自定义过滤器属性的操作...

[UserValidation("Standard")]
public ActionResult Index()

自定义属性定义为...

public class UserValidationAttribute : FilterAttribute, IAutofacActionFilter
{
    public ILogger Logger { get; set; }

    private string _status;

    public UserValidationAttribute (string status)
    {
        // At this point in the code, 'Logger' is null
        _status = status;
    }

    public void OnActionExecuting(HttpActionContext actionContext)
    {
    }

    public void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {
    }
}

我正在将 AutoFac 容器构建为...

var builder = new ContainerBuilder();

builder.RegisterControllers(Assembly.GetExecutingAssembly());

builder.Register(x => new Logger()
                .As<ILogger>()
                .InstancePerHttpRequest();

builder.RegisterFilterProvider();

var container = builder.Build();

System.Web.Mvc.DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

并且由于某种原因,当自定义操作过滤器的构造函数为“命中”时,公共“记录器”属性为空?

任何帮助,将不胜感激。

谢谢

4

0 回答 0