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 8451971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:23:00+00:00 2026-06-10T11:23:00+00:00

I am using MVC 3 with Ninject. I am defining all of my bindings

  • 0

I am using MVC 3 with Ninject. I am defining all of my bindings within Global.asax.cs (a NinjectHttpApplication), in the CreateKernel method.

I also have an HTTP module that runs for all page requests. The module runs its logic on the PreRequestHandlerExecute after the CreateKernel method is already executed.

I would like to have the HTTP Module define a new binding by linking a class type to a specific instance variable that the module is responsible for constructing. Is this possible?

Basically, in the HttpModule, I am trying to run this:

IUserContext userContext = userContextManager.GetUserContext();
Kernel.Bind<IUserContext>().ToConstant(userContext).InRequestScope();
  • 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. Editorial Team
    Editorial Team
    2026-06-10T11:23:02+00:00Added an answer on June 10, 2026 at 11:23 am

    You should not be rebinding per-request – if you have 1000 requests in progress at a time, while it’s possible to have Ninject manage those registrations (e.g. via .Named Bindings using the Binding Metadata facilities), you’re abusing the container for something it’s not supposed to do (for a start, are you going to do lots of busywork making the HttpModule remove the registration after each request? All this is going to do is cause contention as the threads compete for access to the Kernel.

    Your HttpModule instead should stash the relevant info somewhere suitable (HttpContext.Items is generally appropriate, but you might have a better idea?) and then use ToMethod() instead to define a single callback that can retrieve the relevant data that has been stashed when a given request needs to use the info your HttpModule has stashed.

    Something like:

    Kernel.Bind<IUserContext>()
        .ToMethod( ctx=>(IUserContext)HttpContext.Items["userContext"] )
        .InRequestScope();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ninject in my ASP MVC 3 project, I have modified the
I'm using Ninject 2 and the Ninject.Web.MVC and using the NinjectHttpApplication Receiving the following
I'm using Ninject 2 with an ASP.NET MVC web app. All the dependencies are
Hi I'm using ninject with an MVC app. I'm sure I have it setup
I'm using Ninject with an MVC app, also using EF4.1 Code First. I'm getting
I have started using Ninject 2 (downloaded from Github yesterday including the MVC extension
I have a web application made in asp.net mvc, and i am using Ninject
I have an MVC application using Ninject to connect to a single database. Now
I have an ASP.NET MVC 3 application and am using Ninject for injecting dependencies
I am using Ninject 2 with Asp.Net MVC 3. I have following module. public

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.