Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Web.Http
- Imports System.Web.Optimization
- Imports Ninject.Web.Common
- Imports Ninject
- Imports System.Reflection
- Imports EmployeePerformanceCore
- Imports EmployeePerformanceInfrastructure
- Imports Microsoft.Web.Infrastructure.DynamicModuleHelper
- Imports Ninject.Syntax
- <Assembly: WebActivatorEx.PreApplicationStartMethod(GetType(Global.EmployeePerformance.NinjectWebCommon), "Start")>
- <Assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(GetType(Global.EmployeePerformance.NinjectWebCommon), "Stop")>
- Public NotInheritable Class NinjectWebCommon
- Private Sub New()
- End Sub
- Private Shared ReadOnly bootstrapper As New Bootstrapper()
- ''' <summary>
- ''' Starts the application
- ''' </summary>
- Public Shared Sub Start()
- DynamicModuleUtility.RegisterModule(GetType(OnePerRequestHttpModule))
- DynamicModuleUtility.RegisterModule(GetType(NinjectHttpModule))
- bootstrapper.Initialize(AddressOf CreateKernel)
- End Sub
- Public Shared Sub [Stop]()
- bootstrapper.ShutDown()
- End Sub
- ''' <summary>
- ''' Creates the kernel that will manage your application.
- ''' </summary>
- ''' <returns>The created kernel.</returns>
- '''
- Private Shared Function CreateKernel() As IKernel
- Dim kernel = New StandardKernel()
- Try
- kernel.Bind(Of Func(Of IKernel))().ToMethod(Function(ctx) Function() New Bootstrapper().Kernel)
- kernel.Bind(Of IHttpModule)().[To](Of HttpApplicationInitializationHttpModule)()
- RegisterServices(kernel)
- Return kernel
- Catch
- kernel.Dispose()
- Throw
- End Try
- End Function
- ''' <summary>
- ''' Load your modules or register your services here!
- ''' </summary>
- ''' <param name="kernel">The kernel.</param>
- Private Shared Sub RegisterServices(kernel As IKernel)
- kernel.Bind(Of IUserSession)().To(Of HttpUserSession)()
- kernel.Bind(Of IDataContext)().To(Of EFDbContext)().InRequestScope
- kernel.Bind(Of IUserService)().To(Of UserService)()
- kernel.Bind(Of IStorageService).To(Of AzureStorageService).WithConstructorArgument("connstring", ConfigurationManager.AppSettings("StorageConnectionString")) _
- .WithConstructorArgument("accountname", ConfigurationManager.AppSettings("AzureAccountName")) _
- .WithConstructorArgument("containername", ConfigurationManager.AppSettings("AzureContainer"))
- kernel.Bind(Of IMailService)().To(Of MailService).WithConstructorArgument("emailusername", ConfigurationManager.AppSettings("emailusername")) _
- .WithConstructorArgument("emailpassword", ConfigurationManager.AppSettings("emailpassword")) _
- .WithConstructorArgument("emailhost", ConfigurationManager.AppSettings("emailhost")) _
- .WithConstructorArgument("emailport", ConfigurationManager.AppSettings("emailport")) _
- .WithConstructorArgument("emailenablessl", ConfigurationManager.AppSettings("emailenablessl"))
- kernel.Bind(Of IDepartmentService)().To(Of DepartmentService)()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment