Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using SlateCore.BLL.Util;
  2.  
  3. [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(SlateCORE.Web.App_Start.NinjectWebCommon), "Start")]
  4. [assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(SlateCORE.Web.App_Start.NinjectWebCommon), "Stop")]
  5.  
  6. namespace SlateCORE.Web.App_Start
  7. {
  8.     using System;
  9.     using System.Web;
  10.     using System.Configuration;
  11.     using System.Data;
  12.  
  13.     using Microsoft.Web.Infrastructure.DynamicModuleHelper;
  14.  
  15.     using Ninject;
  16.     using Ninject.Web.Common;
  17.     using Ninject.Web.Common.WebHost;
  18.  
  19.     public static class NinjectWebCommon
  20.     {
  21.         private static readonly Bootstrapper bootstrapper = new Bootstrapper();
  22.  
  23.         /// <summary>
  24.         /// Starts the application
  25.         /// </summary>
  26.         public static void Start()
  27.         {
  28.             DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
  29.             DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
  30.             bootstrapper.Initialize(CreateKernel);
  31.         }
  32.        
  33.         /// <summary>
  34.         /// Stops the application.
  35.         /// </summary>
  36.         public static void Stop()
  37.         {
  38.             bootstrapper.ShutDown();
  39.         }
  40.        
  41.         /// <summary>
  42.         /// Creates the kernel that will manage your application.
  43.         /// </summary>
  44.         /// <returns>The created kernel.</returns>
  45.         private static IKernel CreateKernel()
  46.         {
  47.             var modules = new Ninject.Modules.INinjectModule[]
  48.             {
  49.                 //new SlateCore.BLL.Infrastructure.ServiceModule("DefaultConnection")
  50.                 new ServiceModule(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString())
  51.             };
  52.             var kernel = new StandardKernel(modules);
  53.             try
  54.             {
  55.                 kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
  56.                 kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
  57.  
  58.                 RegisterServices(kernel);
  59.                 return kernel;
  60.             }
  61.             catch
  62.             {
  63.                 kernel.Dispose();
  64.                 throw;
  65.             }
  66.         }
  67.  
  68.         /// <summary>
  69.         /// Load your modules or register your services here!
  70.         /// </summary>
  71.         /// <param name="kernel">The kernel.</param>
  72.         private static void RegisterServices(IKernel kernel)
  73.         {
  74.             System.Web.Mvc.DependencyResolver.SetResolver(new SlateCORE.Web.Util.NinjectDependencyResolver(kernel));
  75.         }        
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement