I am using Ninject in an MVC3 application.
One of my resolvable dependencies uses HttpContext.Current.Server.MapPath("~/App_Data")
Back when I initialized the IoC container in Global.asax (Application_Start), I was able to simply define in my module configuration:
.WithConstructorArgument("basePath", HttpContext.Current.Server.MapPath("~/App_Data"));
Since my module was initialized from the same thread as the application, HttContext.Current not null.
Then I had to transfer dependency initialization initialization to the PreAppStart method using WebActivator . Since the HttContext is not yet available in this script, I had to remove my dep parameter initialization.
I worked on the issue by resolving the HttpContext inside my class instance at runtime. But it turned out that this was possible only as long as the instance was called from the request. As soon as I moved the call to the allowed instance to a separate thread (without stopping the generators of the ActionResult controllers), I came to the same problem - I could no longer get the HttpContext . How can I resolve this in my script?
PS It just turned out that I can still just call the method from my dependency from the Global.asax Application and submit the HttpContext from there. However, let me know that this is the best way to do this.
source share