What to use instead of HttpContext when using OWIN without System.Web

馋奶兔 提交于 2019-12-23 19:20:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!