Acessing HttpContext from request-scoped class

Topics: Writing modules
Mar 19, 2011 at 2:03 PM
Edited Mar 19, 2011 at 2:08 PM

I have a class, inherited from IDependency. What is the best way to access HttpContext from my class? I want to access it as early a possible, once HttpContext becomes available.

I tried to add dependency injection for IWorkContextAccessor to my class, and access it from the constructor, but GetContext() returns null then.

Mar 19, 2011 at 11:34 PM

The work context is the way to go. Not sure why GetContext would return null. What is your dependency being injected into? Is it always within the scope of a request or is it a longer-lived object of sorts?

Mar 21, 2011 at 11:46 AM
Edited Mar 21, 2011 at 12:01 PM

Ok, let me spread some light on what I`m trying to make. I`m customizing the DefaultCultureManager class. The intention is to move culture selection logic from the GetCurrentCulture method to another private method, that will be called only once when an HttpContext becomes available. The reason is because GetCurrentCulture method is being called too often.

I looked for some kind of component, that aggregates application-level events, like BeginRequest, and which can be accessed from the DefaultCultureManager, but didn`t find anything.

Mar 21, 2011 at 5:04 PM

A handler maybe?

Mar 21, 2011 at 5:25 PM

Do you mean a content handler? Inheriting DefaultCultureManager form the IContentHandler looks like a hack for me: ) I`m looking for a solution will not go against the existing Orchard architecture and philosophy.

Mar 21, 2011 at 6:01 PM

I'm not telling you to make the culture manager to inherit from handler but to create a handler in addition and to rely on an external service class.