Injecting dependencies into custom Web API action filter attribute with Autofac

后端 未结 4 530
甜味超标
甜味超标 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:31

    In addition to @Toan Nguyen's answer, if you have this...

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

    ... it seems you also need (or may need) the first line below:

    builder.RegisterFilterProvider();
    builder.RegisterType().PropertiesAutowired();
    

    Reference: http://itprojectpool.blogspot.com.au/2014/03/autofac-di-on-action-filters.html

提交回复
热议问题