faizinfy

NinjectWebCommon.vb

Dec 12th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.43 KB | None | 0 0
  1. Imports System.Web.Http
  2. Imports System.Web.Optimization
  3. Imports Ninject.Web.Common
  4. Imports Ninject
  5. Imports System.Reflection
  6. Imports EmployeePerformanceCore
  7. Imports EmployeePerformanceInfrastructure
  8. Imports Microsoft.Web.Infrastructure.DynamicModuleHelper
  9. Imports Ninject.Syntax
  10.  
  11. <Assembly: WebActivatorEx.PreApplicationStartMethod(GetType(Global.EmployeePerformance.NinjectWebCommon), "Start")>
  12. <Assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(GetType(Global.EmployeePerformance.NinjectWebCommon), "Stop")>
  13.  
  14.  
  15. Public NotInheritable Class NinjectWebCommon
  16.     Private Sub New()
  17.     End Sub
  18.  
  19.     Private Shared ReadOnly bootstrapper As New Bootstrapper()
  20.  
  21.     ''' <summary>
  22.     ''' Starts the application
  23.     ''' </summary>
  24.     Public Shared Sub Start()
  25.         DynamicModuleUtility.RegisterModule(GetType(OnePerRequestHttpModule))
  26.         DynamicModuleUtility.RegisterModule(GetType(NinjectHttpModule))
  27.         bootstrapper.Initialize(AddressOf CreateKernel)
  28.     End Sub
  29.  
  30.     Public Shared Sub [Stop]()
  31.         bootstrapper.ShutDown()
  32.     End Sub
  33.  
  34.     ''' <summary>
  35.     ''' Creates the kernel that will manage your application.
  36.     ''' </summary>
  37.     ''' <returns>The created kernel.</returns>
  38.     '''
  39.     Private Shared Function CreateKernel() As IKernel
  40.         Dim kernel = New StandardKernel()
  41.         Try
  42.             kernel.Bind(Of Func(Of IKernel))().ToMethod(Function(ctx) Function() New Bootstrapper().Kernel)
  43.             kernel.Bind(Of IHttpModule)().[To](Of HttpApplicationInitializationHttpModule)()
  44.  
  45.             RegisterServices(kernel)
  46.             Return kernel
  47.         Catch
  48.             kernel.Dispose()
  49.             Throw
  50.         End Try
  51.     End Function
  52.  
  53.     ''' <summary>
  54.     ''' Load your modules or register your services here!
  55.     ''' </summary>
  56.     ''' <param name="kernel">The kernel.</param>
  57.     Private Shared Sub RegisterServices(kernel As IKernel)
  58.  
  59.         kernel.Bind(Of IUserSession)().To(Of HttpUserSession)()
  60.         kernel.Bind(Of IDataContext)().To(Of EFDbContext)().InRequestScope
  61.         kernel.Bind(Of IUserService)().To(Of UserService)()
  62.         kernel.Bind(Of IStorageService).To(Of AzureStorageService).WithConstructorArgument("connstring", ConfigurationManager.AppSettings("StorageConnectionString")) _
  63.                                                                             .WithConstructorArgument("accountname", ConfigurationManager.AppSettings("AzureAccountName")) _
  64.                                                                             .WithConstructorArgument("containername", ConfigurationManager.AppSettings("AzureContainer"))
  65.  
  66.         kernel.Bind(Of IMailService)().To(Of MailService).WithConstructorArgument("emailusername", ConfigurationManager.AppSettings("emailusername")) _
  67.                                                          .WithConstructorArgument("emailpassword", ConfigurationManager.AppSettings("emailpassword")) _
  68.                                                          .WithConstructorArgument("emailhost", ConfigurationManager.AppSettings("emailhost")) _
  69.                                                          .WithConstructorArgument("emailport", ConfigurationManager.AppSettings("emailport")) _
  70.                                                          .WithConstructorArgument("emailenablessl", ConfigurationManager.AppSettings("emailenablessl"))
  71.  
  72.         kernel.Bind(Of IDepartmentService)().To(Of DepartmentService)()
  73.  
  74.     End Sub
  75. End Class
Advertisement
Add Comment
Please, Sign In to add comment