服务堆栈:GetSession 和 SessionAs<t> 之间的区别 [英] Service stack: Difference between GetSession and SessionAs&lt;t&gt;

查看:48
本文介绍了服务堆栈:GetSession 和 SessionAs<t> 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Service.GetSession()Service.SessionAs<T>() 和它们如何解决会话之间是否存在显着差异?

Are there any significant differences between Service.GetSession() and Service.SessionAs<T>() and how they resolve the sessions?

我正在维护此代码,该代码在某些请求中使用一个,而在其他请求中使用后者.是否可以互换或有其他一些考虑?

I'm maintaining this code that makes use of one in some requests and uses the later in others. Are there interchangeable or are their some other considerations?

推荐答案

正是这个区别

public virtual IAuthSession GetSession(bool reload = false)
{
    var req = this.Request;
    if (req.GetSessionId() == null)
        req.Response.CreateSessionIds(req);
    return req.GetSession(reload);
}

protected virtual TUserSession SessionAs<TUserSession>()
{
    var ret = TryResolve<TUserSession>();
    return !Equals(ret, default(TUserSession))
        ? ret 
        : Cache.SessionAs<TUserSession>(Request, Response);
}

我从来没有用过它们,但似乎不应该随意互换.您可以在此处浏览此源代码并了解如何他们有很大的不同.由于缺乏文档,乍一看很难说

I have never used any of them, but it seems that they should not be randomly interchanged. You can browse this source code here and figure out how significantly different they are. It's hard to tell at the first glance due to the lack of documentation

这篇关于服务堆栈:GetSession 和 SessionAs<t> 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆