I'musing的ASP.NET Web API,我需要獲得授權,所以我已經創建自定義授權屬性自定義過濾器的屬性注入依賴
public class CustomAuthorizationAttribute : AuthorizeAttribute
爲了注入內部構造依賴我有以下幾點:
public CustomAuthorizationAttribute(IAccountBL accountBl)
{
_accountBL = accountBl;
}
在IAccountBL
我有方法與數據庫檢查交互如果用戶被授權發出請求。 內部會員API控制器我已經註冊該屬性
[CustomAuthorization]
public class MemberController : ApiController
,但我得到以下錯誤
Project.Account.AccountBL」不包含一個構造函數參數0
如果我註冊它就像
[CustomAuthorization(IAccountBL)]
謝謝
這可能幫助:http://stackoverflow.com/questions/6193414/依賴注入與ninject和過濾器屬性的asp網絡mvc –