Injecting dependencies into custom Web API action filter attribute with Autofac

后端 未结 4 529
甜味超标
甜味超标 2021-02-05 06:15

I\'m trying to resolve the dependencies of my custom AuthorizeAttribute which I use to decorate my API controllers in an MVC4 app. Problem is that I keep getting a

4条回答
  •  醉酒成梦
    2021-02-05 06:25

    You should configure property injection for your attribute

    public class MyAuthorizeAttribute : AuthorizeAttribute
    {
        public IAuthenticationSvc AuthenticationSvc { get; set; }
    }
    

    and the builder

    builder.RegisterType().PropertiesAutowired();
    

提交回复
热议问题