When I make a post for my controller, when debugging, I saw that the service which I load in my constructor, is coming null type.
Controller:
public class UserController : ApiController
{
private static IUserService _userService;
public UserController(IUserService userService)
{
_userService = userService;
}
[System.Web.Http.HttpGet]
public IHttpActionResult GetUserById(long id)
{
var user = _userService.GetById(id);
return Ok(user);
}
[HttpPost]
[Route("api/User/Insert")]
public IHttpActionResult Insert(User user)
{
user.StartDate = DateTime.Now;
_userService.Register(user);
return Ok();
}
}
Debug error return:
Controller 'does not have a default constructor', 'Exception Type': "System.ArgumentException", "StackTrace"