I am wiring up Ninject with MVC4 and have it working to the point it’s trying to actually resolve dependencies. However, I am getting the following exception:
Method not found: ‘System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()’.
Anyone ran into this and have a work around?
GlobalConfiguration.Configuration.ServiceResolverwas replaced withGlobalConfiguration.Configuration.DependencyResolverin the RC. So I guess the Ninject package you are using is simply not designed for the RC. It was one of the breaking changes.So here are the steps to make Ninject work with ASP.NET MVC 4 Web API RC:
Declare an interface:
Then an implementation:
Then add an API controller:
Install the
Ninject.Mvc3NuGet package (Install-Package Ninject.Mvc3)Define a custom API dependency resolver as shown in this gist:
In your
~/App_Start/NinjectWebCommon.cs/CreateKernelmethod that was created when you installed the NuGet add the following line after theRegisterServices(kernel);line:Configure your kernel:
Hit F5 and navigate to
/api/valuesthe bar.Obviously when the RC hits RTM I hope there will be a
Ninject.Mvc4NuGet that will shorten those 10 steps to maximum 5.