[assembly: WebActivator.PreApplicationStartMethod(typeof($rootnamespace$.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof($rootnamespace$.App_Start.NinjectWebCommon), "Stop")]
namespace $rootnamespace$.App_Start
{
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
///
/// Starts the application
///
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
///
/// Stops the application.
///
public static void Stop()
{
bootstrapper.ShutDown();
}
///
/// Creates the kernel that will manage your application.
///
/// The created kernel.
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind().To();
RegisterServices(kernel);
return kernel;
}
///
/// Load your modules or register your services here!
///
/// The kernel.
private static void RegisterServices(IKernel kernel)
{
}
}
}