I tried the solution in MVC5, Web API 2 and and Ninject but the package breaks my build(System.Web). I have also tried the "Ninject.MVC3" Package. When i fix it with "Update-Package -reinstall Microsoft.AspNet.WebApi.WebHost", I get the error:
An error occurred when trying to create a controller of type error: 'AnyController'. Make sure that the controller has a parameterless public constructor.
I have installed, reinstalled, uninstalled-installed all the of the packages multiple times.
My NinjectWebCommon.cs is vanilla except for the following:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IMonitoringConfigurationService>()
.To<MonitoringConfigurationService>();
}
I Would be very grateful for any help
Not sure what the cause of your problem is, as the latest releases of Ninject are virtually plug-n-play. Make sure you have installed the following Nuget packages. If you've got other versions or anything weird uninstall them:
Anything else is unnecessary and should be removed. The last two packages are installed as dependencies, so really all you should have to install explicitly is
Ninject.MVC5andNinject.Web.WebApi. Either will install theNinjectbase package.Once you've got the right packages, then it basically boils down to your config in
NinjectWebCommon.cs. The only method you need to modify isRegisterServices, and there, you'll need to add any and all bindings your project needs. If you're getting an error saying you need a parameterless constructor, that just means you haven't added the binding that the constructor needs.