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
In addition to configuring property injection, as outlined in other answers, you can also explicitly resolve dependencies in the OnActivating
callback.
public class MyAuthorizeAttribute : AuthorizeAttribute
{
private IAuthenticationSvc _authenticationSvc;
public void SetAuthenticationSvc(IAuthenticationSvc svc)
{
this._authenticationSvc = svc;
}
}
And then register the type:
builder.RegisterType()
.OnActivating(_ => _.Instance.SetAuthenticationSvc(_.Context.Resolve()));
Note: You can do the same with a property instead of a method. I chose to use a method here only to illustrate that this solution was not dependent on PropertiesAutowired
.