Skip to content

Instantly share code, notes, and snippets.

@Aaronontheweb
Created May 17, 2012 19:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aaronontheweb/2721187 to your computer and use it in GitHub Desktop.
Save Aaronontheweb/2721187 to your computer and use it in GitHub Desktop.
Ninject for MVC4 WebApi
/* This is part of the file that is generated automatically when you install Ninject.MVC3 -pre via Nuget */
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
//Creates a dependency resolver for Web API controllers specifically
var resolver = new NinjectDependencyResolver(kernel);
GlobalConfiguration.Configuration.ServiceResolver.SetResolver(resolver.GetService, resolver.GetServices);
return kernel;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment