2

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

Community
  • 1
  • 1

1 Answers1

0

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:

Ninject
Ninject.MVC5
Ninject.Web.WebApi
Ninject.Web.Common (Added by Ninject.Web.WebApi)
Ninject.Web.Common.WebHost (Added by Ninject.MVC5)

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.MVC5 and Ninject.Web.WebApi. Either will install the Ninject base 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 is RegisterServices, 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.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444