[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(WebAPI.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(WebAPI.App_Start.NinjectWebCommon), "Stop")]
namespace WebAPI.App_Start
{
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
using Ninject.Web.Common.WebHost;
using Repository.Abstract;
using Repository.Concrete;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
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.
public static IKernel CreateKernel()
{
var kernel = new StandardKernel();
try
{
kernel.Bind>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind().To();
RegisterServices(kernel);
System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = new Ninject.WebApi.DependencyResolver.NinjectDependencyResolver(kernel);
return kernel;
}
catch
{
kernel.Dispose();
throw;
}
}
///
/// Load your modules or register your services here!
///
/// The kernel.
private static void RegisterServices(IKernel kernel)
{
}
}
}