Krishna Kumar

Krishna Kumar

  • NA
  • 135
  • 38.6k

InterFace And WebApi.. NullReference Exception

Nov 28 2016 3:11 AM
public interface ILoginManager
{
IEnumerable<HR_Login> GetLogins();
}
I have declared this methods in the interface and implemented in below class
 
class LoginManager : ILoginManager
{
private readonly ILoginRespository _loginRepository;
public LoginManager(ILoginRespository loginRepository)
{
_loginRepository = loginRepository;
}
public HR_Login Create(HR_Login login)
{
return _loginRepository.Create(login);
}
 Now i am trying to access the method in webapi
 
private readonly ILoginManager _loginManager;
public LoginController()
{
}
public LoginController(ILoginManager loginManager)
{
this. _loginManager = loginManager;
}
[HttpGet, Route("logins")]
public HttpResponseMessage Get()
{
return Request.CreateResponse(HttpStatusCode.OK, _loginManager.GetLogins());
}
 
 And when i complied this code... It is giving mr the Null Reference exception in the controller GET Method.

Answers (4)