Ninject & WebAPI: Getting Started After Installing From NuGet
I installed the Ninject Integration NuGet package for WebApi2 through the Package Manager Console.
According to the wiki on the project's GitHub pages , this should have created a class named NinjectWebCommon
in the App_Start folder. But this is not the case.
This GitHub wiki page explains what you should see so you can add it yourself. So I tried to create a class NinjectWebCommon
. The problem here is that I cannot find the namespace for OnePerRequestModule
in the following snippet.
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
The alternative, and according to this GitHub wiki, there is no effective difference between the two, is to change global.asax. So I tried this method and added some bindings like this
private void RegisterServices(IKernel kernel)
{
kernel.Bind<IEntityAccess>().To<EntityAccess>();
kernel.Bind<IDictionaryRepository>().To<DictionaryRepository>();
}
and found that my project is building, but when the request is sent to the WebAPI project, it cannot be found (i.e. I get a 404 response).
So, there is obviously another piece of required wiring that is missing from my project.
It looks like, despite changing mine global.asax
to output from NinjectHttpApplication
, global.asax
no longer gets called.
Can anyone tell me what I might be missing? I have uninstalled and re-installed the NuGet package several times, but the class NinjectWebCommon
never appears and my global.asax file is never modified.
I've also read Ninject's own documentation , but unfortunately it's a pretty long tutorial covering the basics of IoC and how Ninject works, rather than telling you how to get started using Ninject.
There's also this SO post asking how to get started with Ninject for WebAPI, so it looks like there is something wrong with their NuGet package.
source to share