Created April 16, 2011 23:34
-
-
Save graylikeme/923618 to your computer and use it in GitHub Desktop.
Ninject MVC3 loader in VB(NinjectMVC3.vb)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Imports Microsoft.Web.Infrastructure.DynamicModuleHelper | |
| Imports Ninject | |
| Imports Ninject.Web.Mvc | |
| <Assembly: WebActivator.PreApplicationStartMethod(GetType(applicationName.App_Start.NinjectMVC3), "StartNinject")> | |
| <Assembly: WebActivator.ApplicationShutdownMethodAttribute(GetType(applicationName.App_Start.NinjectMVC3), "StopNinject")> | |
| Namespace applicationName.App_Start | |
| Public Module NinjectMVC3 | |
| Private ReadOnly bootstrapper As New Bootstrapper() | |
| ''' <summary> | |
| ''' Starts the application | |
| ''' </summary> | |
| Public Sub StartNinject() | |
| DynamicModuleUtility.RegisterModule(GetType(OnePerRequestModule)) | |
| bootstrapper.Initialize(AddressOf CreateKernel) | |
| End Sub | |
| ''' <summary> | |
| ''' Stops the application. | |
| ''' </summary> | |
| Public Sub StopNinject() | |
| bootstrapper.ShutDown() | |
| End Sub | |
| ''' <summary> | |
| ''' Creates the kernel that will manage your application. | |
| ''' </summary> | |
| ''' <returns>The created kernel.</returns> | |
| Private Function CreateKernel() As IKernel | |
| Dim kernel = New StandardKernel() | |
| RegisterServices(kernel) | |
| Return kernel | |
| End Function | |
| ''' <summary> | |
| ''' Load your modules or register your services here! | |
| ''' </summary> | |
| ''' <param name="kernel">The kernel.</param> | |
| Private Sub RegisterServices(ByVal kernel As IKernel) | |
| End Sub | |
| End Module | |
| End Namespace |
Author
really? i'll check this out at the morning, but as far as i'm concerned that when you install through nuget then everything should work as a charm
Its because of recent changes in Ninject. Now the class is called OnePerRequestHttpModule Here is my revision to the code which is working for me now: Imports Microsoft.Web.Infrastructure.DynamicModuleHelper Imports Ninject.Web.Common Imports Ninject.Web Imports Ninject Imports Ninject.Web.Mvc <Assembly: WebActivator.PreApplicationStartMethod(GetType(applicationName.App_Start.NinjectWebCommon), "StartNinject")> <Assembly: WebActivator.ApplicationShutdownMethodAttribute(GetType(applicationName.App_Start.NinjectWebCommon), "StopNinject")> Namespace applicationName.App_Start Public Module NinjectWebCommon Private ReadOnly bootstrapper As New Bootstrapper() ``` ''' <summary> ''' Starts the application ''' </summary> Public Sub StartNinject() DynamicModuleUtility.RegisterModule(GetType(NinjectHttpModule)) DynamicModuleUtility.RegisterModule(GetType(OnePerRequestHttpModule)) bootstrapper.Initialize(AddressOf CreateKernel) End Sub ''' <summary> ''' Stops the application. ''' </summary> Public Sub StopNinject() bootstrapper.ShutDown() End Sub ''' <summary> ''' Creates the kernel that will manage your application. ''' </summary> ''' <returns>The created kernel.</returns> Private Function CreateKernel() As IKernel Dim kernel = New StandardKernel() kernel.Bind(Of Func(Of IKernel))().ToMethod(Function(ctx) Function() New Bootstrapper().Kernel) kernel.Bind(Of IHttpModule)().To(Of HttpApplicationInitializationHttpModule)() RegisterServices(kernel) Return kernel End Function ''' <summary> ''' Load your modules or register your services here! ''' </summary> ''' <param name="kernel">The kernel.</param> Private Sub RegisterServices(ByVal kernel As IKernel) kernel.Load(New Bindings.ServiceBindings(), New Bindings.RepositoryBindings(), New Bindings.PresentationBindings(), New Bindings.CrossCuttingBindings()) End Sub End Module ``` End Namespace
…-----Original Message----- From: Stanislav Ageev [mailto:reply@reply.github.com] Sent: Saturday, April 28, 2012 10:37 PM To: schmidlop Subject: Re: gist gist: 923618 really? i'll check this out at the morning
--- Reply to this email directly or view it on GitHub: https://gist.github.com/923618 ## ## BEGIN-ANTISPAM-VOTING-LINKS Teach Transbeam CanIt if this mail (ID 273786583) is spam: Spam: http://mailshield.cosmoweb.net/canit/b.php?i=273786583&m=b225cdb50401&c=s Not spam: http://mailshield.cosmoweb.net/canit/b.php?i=273786583&m=b225cdb50401&c=n ## Forget vote: http://mailshield.cosmoweb.net/canit/b.php?i=273786583&m=b225cdb50401&c=f END-ANTISPAM-VOTING-LINKS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Is there an update to this code? I am getting OnePerRequestModule is not defined....