问题
We currently have a NancyFx project that we have wired up using OWIN. We are not using System.Web and we need some place to put our context that lives for the life of a request other than HttpContext. We have started implementing the context on a thread static variable so we can access the context anywhere in the application but we are worried that using Async calls will lose this thread static context.
What do you use as a static accessor in lue of HttpContext when you divorce yourself from System.Web?
回答1:
You can use the NancyContext instead. The Items dictionary on the NancyContext is for storing per-request objects. The NancyContext is available most anywhere in a Nancy application.
回答2:
This thread might answer your question : https://groups.google.com/forum/#!topic/nancy-web-framework/yILM4ZMrsSQ
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureRequestContainer(
TinyIoCContainer container, NancyContext context)
{
base.ConfigureRequestContainer(container, context);
container.Register<ICurrentRequest>(
(c, o) => new CurrentRequest(context));
}
private class CurrentRequest : ICurrentRequest
{
public CurrentRequest(NancyContext context)
{
this.Context = context;
}
public NancyContext Context { get; private set; }
}
}
来源:https://stackoverflow.com/questions/23814265/what-to-use-instead-of-httpcontext-when-using-owin-without-system-web