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, but the remainder of articles involve complex setups with factories, locators, global wrappers or stub attributes.
With MVC allowing you to override almost any part of it's operation I would have thought it would be simply a case of creating your own filter provider in a similar fashion to how you create your own dependency resolver.
What is the now correct way to allow injection, or does it become easier if you use certain types of filters vs others?
public class UserValidationAttribute : ActionFilterAttribute
{
private IRepository repository;
public UserValidationAttribute(IRepository repository)
{
this.repository = repository;
}
}
filterContext.ActionDescriptor.IsDefined(typeof(MyTokenAttribute), true)
I gettrue
, but if I only put the token attribute on the controller I getfalse
. – Nudity