Hey there, I\'ve succesfull been able to use property injection in my FilterAttribute, however I\'m wondering whether its possible to move it into the constructor instead?>
No, this isn't possible as the parameters for the constructors must be simple types.
For testing purposes, you could have another constructor (since you shouldn't be using an IoC container with testing):
public class AuthAttribute : ActionFilterAttribute
{
public Roles _authRoles { get; private set; }
[Inject]
private readonly IAuthorizationService _service;
public AuthAttribute(Roles roles)
{
_authRoles = roles;
}
public AuthAttribute(Roles roles, IAuthorizationService authSvc)
: this(roles)
{
this.service = authSvc;
}
// ...
}