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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:19:32+00:00 2026-05-29T06:19:32+00:00

I am using Ninject in MVC3 application. One of my resolvable dependencies makes use

  • 0

I am using Ninject in MVC3 application.

One of my resolvable dependencies makes use of HttpContext.Current.Server.MapPath("~/App_Data")

Back when I was initializing an IoC container in Global.asax (Application_Start), I was able to just define in my module configuration:

.WithConstructorArgument("basePath", HttpContext.Current.Server.MapPath("~/App_Data"));

Since my module was being initialized from the same thread as the Application, HttContext.Current wasn’t null.

Then I had to move my Dependency Injection initialization to an PreAppStart method, using the WebActivator. Since the HttContext is not yet available in this scenario, I had to remove the parameter initialization of my dep.

I had worked around the problem by resoling the HttpContext inside my class instance at runtime. But it turns out it was possible only as long as the instance was being called from the Request Thread. As soon as I have moved the resolved instance call to a separate thread (not to be halting the Controllers’ ActionResult generation), I arrived at the same problem – no longer able to get HttpContext. How can I resolve it in my scenario?

P.S. Just figured out I still can just call a method on my dependency from Global.asax Application start and feed the HttpContext from there. Nevertheless, let me know which is the best way to do it.

  • 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-05-29T06:19:33+00:00Added an answer on May 29, 2026 at 6:19 am

    There should be a way in Ninject to register the dependency in a lazy way using a delegate. This way it will only resolve it when you access the dependency.

    Here is how I do it using StructureMap:

    For<HttpContextBase>().Use(c => new HttpContextWrapper(HttpContext.Current));
    

    As far as accessing the HttpContext from a different thread, you can use the AsyncManager.Sync(d) method that takes a delegate and runs it in the ASP .NET worker process.

    • 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 MVC 3 application and one of my dependencies
I'm using EF 4.3 in an MVC4 application and Ninject.MVC3. Controllers are MVCscaffolded using
I am using Ninject together with MVC3 to inject my controller dependencies. Sometimes I
I've got a simple web application using ASP.NET MVC3 and Ninject.Web.MVC (the MVC3 version).
I am currently creating an MVC3 application using Ninject. I have two controllers which
I'm starting a web application with MVC3 and Ninject. There is one dependency that
I have an ASP.NET MVC 3 application and am using Ninject for injecting dependencies
I am using ASP.NET MVC 3 + Ninject in my application which works great
I am new to ninject using ninject 2.0. My application is hosted in asp.net
I'm using Ninject 2 with an ASP.NET MVC web app. All the dependencies are

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.