I am trying to develop an application, through a book, in WebApi. It is a simple application but whenever I am testing this application using fiddler, it is throwing error - {"Message":"An error occurred when trying to create a controller of type 'TasksController'. Make sure that the controller has a parameterless public constructor."}. I am using ninject for dependency injection. Here is some of my code:
public class NinjectConfigurator
{
public void Configure(IKernel container)
{
AddBindings(container);
}
private void AddBindings(IKernel container)
{
ConfigureLog4net(container);
ConfigureNHibernate(container);
ConfigureUserSession(container);
ConfigureAutoMapper(container);
container.Bind<IDateTime>().To<DateTimeAdapter>().InSingletonScope();
container.Bind<IAddTaskQueryProcessor>().To<IAddTaskQueryProcessor>().InRequestScope();
container.Bind<IAddTaskMaintenanceProcessor>().To<AddTaskMaintenanceProcessor>().InRequestScope();
}
}
public class TasksController : ApiController
{
private readonly IAddTaskMaintenanceProcessor _addTaskMaintenanceProcessor;
//public TasksController() { }
public TasksController(IAddTaskMaintenanceProcessor addTaskMaintenanceProcessor)
{
_addTaskMaintenanceProcessor = addTaskMaintenanceProcessor;
}
[Route("", Name="AddTaskRoute")]
[HttpPost]
public Task AddTask(HttpRequestMessage requestMessage, NewTask newTask)
{
var task = _addTaskMaintenanceProcessor.AddTask(newTask);
return task;
}
}
I am not sure why I am getting the error. I am following all the instructions of the book. Please help!!