Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 128833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:41:52+00:00 2026-05-11T05:41:52+00:00

I’ve been using Ninject as my IOC in my web app. It’s great and

  • 0

I’ve been using Ninject as my IOC in my web app. It’s great and I think it works really well, however I have been trying to register some interfaces / classes as OnePerRequestBehaviour but it doesn’t seem to actually use the behaviour. The code runs correctly but in one of my classes it lazy loads page information from the database then once it has been loaded it doesn’t need to hit the database.

My problem is that the lazily loaded property will load in my first request, when I then request the next page the same instance of the class is used. The reason I know this is because the class is not instantiated again and the lazily loaded property is already set.

This code is within my module class :

public class NinjectModule : StandardModule {     public override void Load()     {         Bind<IUnitOfWorkDataStore>().To<HttpContextDataStore>().Using<OnePerRequestBehavior>();           Bind<CmsService>().ToSelf().Using<OnePerRequestBehavior>();         Bind<CmsRepository>().ToSelf().Using<OnePerRequestBehavior>();     } } 

Then inside my Global.asax which inherits from NinjectHttpApplication I have the following:

        protected override IKernel CreateKernel()         {             OnePerRequestModule module = new OnePerRequestModule();             module.Init(this);              KernelOptions options = new KernelOptions();             options.InjectNonPublicMembers = true;              IKernel kernel = new StandardKernel(options, new NinjectModule());              return kernel;         } 

The first call made to CmsService is within the global.asax as well on authenticate_request:

protected void Application_AuthenticateRequest(object sender, EventArgs e)         {             if (HttpContext.Current.Request.Url.AbsoluteUri.Contains('.aspx') &&                 !HttpContext.Current.Request.Url.AbsoluteUri.Contains('.aspx/'))             {                 CmsService facCMS = HttpKernelFactory.Get<CmsService>();                 ContentPage page = facCMS.GetCurrentPage();                  // DO Logic based on the page being brought back             }         } 

The above GetCurrentPage() code:

public ContentPage GetCurrentPage() {     if (_currentPage != null)         return _currentPage;      return GetCurrentPage(_isAdmin); } 

So as you can see the _currentPage variable is only loaded if it hasn’t been set before, which should be once per request, however Ninject doesn’t seem to be creating the CmsService per request it seems to create it for an abritrary amount of time.

Deos anyone have any idea of why this isn’t working for me or any example code of where it definately does work?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:41:52+00:00Added an answer on May 11, 2026 at 5:41 am

    The OnePerRequestModule is an HttpModule, and needs to be loaded into your ASP.NET pipeline in order to work. If you add it to your web.config, it should work:

    IIS7:

    <system.webServer>    <modules>     <add name='OnePerRequestModule' type='Ninject.Core.Behavior.OnePerRequestModule, Ninject.Core'/>   </modules> </system.webServer> 

    IIS6:

    <system.web>   <httpModules>     <add name='OnePerRequestModule' type='Ninject.Core.Behavior.OnePerRequestModule, Ninject.Core'/>   </httpModules> </system.web> 

    The OnePerRequest behavior is greatly improved in Ninject2 (which is yet to be released).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.