Filter constructor injection using Ninject

后端 未结 3 2140
我寻月下人不归
我寻月下人不归 2021-02-08 04:30

I am trying to find a way to use Ninject to inject constructor dependencies into filters. I am finding many articles describing property injection which is now advised against,

3条回答
  •  生来不讨喜
    2021-02-08 05:02

    If you want to inject dependencies to a filer, you want to use property injection instead of constructor injection.

    public class UserValidationAttribute : ActionFilterAttribute
    {
        [Inject]
        private IRepository repository { get; set; }
    
        public UserValidationAttribute()
        {
        }
    }
    

    https://stackoverflow.com/a/7192754/296861

提交回复
热议问题