我对 ASP .NET Web API 有疑问。我已按照教程http://www.asp.net/web-api/overview/security/basic-authentication并已成功将其与示例代码一起使用。但是我想将它与我所做的 AuthenticationService 绑定:
public class AuthenticationService : IAuthenticationService
{
private readonly GenericRepository<User> _userRepository;
public AuthenticationService(GluEntities entites)
{
_userRepository = new GenericRepository<User>(entites);
}
public bool Authenticate(string userName, string password)
{
var user = _userRepository.Get(x => x.UserName == userName).FirstOrDefault();
if (user == null || user.Password != password)
{
return false;
}
return true;
}
}
我试图将它与我的示例代码联系起来,如下所示:
public class BasicAuthHttpModule : IHttpModule
{
private const string Realm = "GluService";
private readonly IAuthenticationService _authenticationService;
public BasicAuthHttpModule(IAuthenticationService authenticationService)
{
_authenticationService = authenticationService;
}
/... some irrelevant methods that are explained in the link
private bool CheckPassword(string username, string password)
{
return _authenticationService.Authenticate(username, password);
}
}
我正在尝试使用 ninject 解决 _authenticationService,但是应用程序在运行时抛出 Conustructor not found 错误。知道如何在运行时解析 _authenticationService 以便实现可维护性和可测试性吗?