PerRequestTask - missing execution context

Jun 1, 2010 at 8:55 PM
Edited Jun 1, 2010 at 8:56 PM

Hello,

As you mentioned you had refactored Bootstrapper/PerRequestTask. For now there is no PerRequestExecutionContext passed into Execute method. How can I access HttpContext or ServiceLocator inside the PerRequestTask now? Should I inject them manually or I can use some infrastructure?

Thank you.

Coordinator
Jun 1, 2010 at 9:16 PM

The HttpContext is registered in the container when the container is created. You can either pass it in the ctor or you can use the ServiceLocator.GetInstance<HttpContextBase>().

Jun 1, 2010 at 9:25 PM

I think you mean ServiceLocator.Current.GetInstance<HttpContextBase>(), right?

 

Coordinator
Jun 1, 2010 at 9:49 PM

All three are supposted:

public class MyClass
{
    private readonly HttpContextBase;

    public class(HttpContextBase httpContext)
    {
        this.httpContext = httpContext;
    }
}
public class MyClass
{
    private IServiceLocator serviceLocator;

    public class MyClass(IServiceLocator serviceLocator)
    {
        this.serviceLocator = serviceLocator;
    }
}
And you can also call ServiceLocator.Current.GetInstance<HttpContextBase>();
Jun 1, 2010 at 10:10 PM

Thank you a lot.

And please take a look at the stackoverflow issue (http://mvcextensions.codeplex.com/WorkItem/View.aspx?WorkItemId=1). I have it with the UnityAdapter (the latest trunk source)