I'm struggling with enabling Ninject's constructor injection in a Web Service application. Here's the steps I took (Visual Studio 2013):
1) Created a new project with "ASP.NET Web Application" template.
2) Selected an "Empty" application template in the second step of the project creation wizard.
3) In the third step called "Add folders and core references for" selected "Web API"
4) The project is created, now I added a controller of type "Web API 2 Controller - Empty". Added the following code:
using System.Web.Http;
namespace WebApplication1.Controllers
{
public interface IDummy
{
}
public class Dummy : IDummy
{
}
public class DefaultController : ApiController
{
public DefaultController(IDummy dummy)
{
}
[HttpGet]
[Route("")]
public string Index()
{
return "Hello World!";
}
}
}
5) Installed NuGet package: Ninject.Web.WebApi (Ninject integration for WebApi2), now I've found in other threads that to make it work with IIS I need to install Ninject.Web.Common.WebHost package. After this, the NinjectWebCommon.cs file appeared in AppStart. The only edit I did for this file was in RegisterServices method:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IDummy>().To<Dummy>();
}
Now when I try to run the application (locally, just pressing F5 in Visual Studio) I would expect to get the Hello World string in a browser, but instead I get the infamous parameterless constructor error:
which means that the Ninject is for some reason not doing its job I guess. Unfortunately googling for solution was fruitless so far. Anyone can hint me what should I do to make this work? Thanks in advance.