I'musing ASP.NET Web API and I need to have authorization so I've created custom authorization attribute
public class CustomAuthorizationAttribute : AuthorizeAttribute
public CustomAuthorizationAttribute(IAccountBL accountBl)
{
_accountBL = accountBl;
}
IAccountBL
[CustomAuthorization]
public class MemberController : ApiController
Project.Account.AccountBL' does not contain a constructor that takes 0 arguments
[CustomAuthorization(IAccountBL)]
If anyone finds similar issue here's how I manage to solve it.
My custom filter inherits IAutofacAuthorizationFilter
. Besides this one you can also inherit IAutofacExceptionFilter
and IAutofacActionFilter
.
And inside my DI container I've register this filter for each controller I want to use like this
builder.Register(c => new CustomAuthorizationAttribute(c.Resolve<IAccountBL>()))
.AsWebApiAuthorizationFilterFor<MemberController>()
.InstancePerApiRequest();