Search Results

Search found 2 results on 1 pages for 'oneperrequestmodule'.

Page 1/1 | 1 

  • Ninject.Web, OnePerRequestModule, and IIS7 Integrated Pipeline

    - by Ted
    Using Ninject.Web with ASP.NET WebForms project. Works without issues using classic pipeline, but when it's under integrated pipeline, a null reference exception occurs on every request (which I've narrowed down to the use of the OnePerRequestModule): [NullReferenceException: Object reference not set to an instance of an object.] System.Web.PipelineStepManager.ResumeSteps(Exception error) +1216 System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +113 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +616 The above always occurs unless I remove the OnePerRequestModule initializization. occurs consistently on a very basic test app I put together. On a standard app where I actually want to implement it, I can solve the issue by initializing the OnePerRequestModule like so: protected override IKernel CreateKernel() { // This will always blow up. //var module = new OnePerRequestModule(); //module.Init(this); IKernel kernel = new StandardKernel(new MyModule()); // This works on larger app, but on basic app, it makes no difference under integrated pipeline as the above exception is always thrown. var module = new OnePerRequestModule(); module.Init(this); return kernel; } Before I start spelunking further, is anybody out there using Ninject.Web extension successfully under the integrated pipeline in IIS7 AND using the OnePerRequestModule? There are certain restrictions for modules under the integrated pipeline that weren't there in previous IIS versions/classic pipeline. Quickly thrown together sample project at http://www.filedropper.com/test_59 And in case it's not obvious with Ninject.Web: it's an ASP.NET WebForms project.

    Read the article

  • Ninject.Web.PageBase still resulting in null reference to injected dependency

    - by Ted
    I have an ASP.NET 3.5 WebForms application using Ninject 2.0. However, attempting to use the Ninject.Web extension to provide injection into System.Web.UI.Page, I'm getting a null reference to my injected dependency even though if I switch to using a service locator to provide the reference (using Ninject), there's no issue. My configuration (dumbed down for simplicity): public partial class Default : PageBase // which is Ninject.Web.PageBase { [Inject] public IClubRepository Repository { get; set; } protected void Page_Load(object sender, EventArgs e) { var something = Repository.GetById(1); // results in null reference exception. } } ... //global.asax.cs public class Global : Ninject.Web.NinjectHttpApplication { /// <summary> /// Creates a Ninject kernel that will be used to inject objects. /// </summary> /// <returns> /// The created kernel. /// </returns> protected override IKernel CreateKernel() { IKernel kernel = new StandardKernel(new MyModule()); return kernel; } .. ... public class MyModule : NinjectModule { public override void Load() { Bind<IClubRepository>().To<ClubRepository>(); //... } } Getting the IClubRepository concrete instance via a service locator works fine (uses same "MyModule"). I.e. private readonly IClubRepository _repository = Core.Infrastructure.IoC.TypeResolver.Get<IClubRepository>(); What am I missing? [Update] Finally got back to this, and it works in Classic Pipeline mode, but not Integrated. Is the classic pipeline a requirement? [Update 2] Wiring up my OnePerRequestModule was the problem (which had removed in above example for clarity): protected override IKernel CreateKernel() { var module = new OnePerRequestModule(); module.Init(this); IKernel kernel = new StandardKernel(new MyModule()); return kernel; } ...needs to be: protected override IKernel CreateKernel() { IKernel kernel = new StandardKernel(new MyModule()); var module = new OnePerRequestModule(); module.Init(this); return kernel; } Thus explaining why I was getting a null reference exception under integrated pipeline (to a Ninject injected dependency, or just a page load for a page inheriting from Ninject.Web.PageBase - whatever came first).

    Read the article

1