- Ninject
- Ninject.Web.Common
- Ninject.Web.Common.WebHost
- Ninject.Web.Mvc5
Most of the magic is done in NinjectWebCommon.cs file. In that class you can add your bindings like the following:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<ISomeInterface>().To<SomeImplementation>();
}
If you have lot of bindings in your project it may become difficult to implement the above approach. In such instances its best to make use of the NinjectModule, like below:
private static void RegisterServices(IKernel kernel)
{
kernel.Load(Assembly.GetExecutingAssembly());
}
Then somewhere in your project you create a class that is derived from NinjectModule, eg.
public class RepositoryModule: NinjectModule
{
public override void Load()
{
this.Bind<ISomeInterface>().To<SomeImplementation>();
}
}
you can define as many module classes as it fits for the project
- Ninject
- Ninject.Web.Common
- Ninject.Web.Common.WebHost
- Ninject.Web.WebApi
- Ninject.Web.WebApi.WebHost
Again, NinjectWebCommon.cs handles all the plumbing for you, and bindings could be handled individually in the RegisterServices method in separate NinjectModule derived classes.
It is very important that the Ninject.Web.WebApi.WebHost package is installed in your Web Api project, otherwise you have to write your own IDependencyResolver implementation
- Ninject
- Ninject.Web.Common
- Ninject.Web.Common.WebHost
- Ninject.Web.WebApi
- Ninject.Web.WebApi.WebHost
- Ninject.Web.Mvc5
For the Web Api, just make sure Ninject.Web.WebApi.WebHost is installed