从 ServiceStackController 继承的 MVC 控制器中的以下三行之间的确切区别是什么 [英] What's the precise differences between the following three lines in a MVC controller inheriting from ServiceStackController

查看:29
本文介绍了从 ServiceStackController 继承的 MVC 控制器中的以下三行之间的确切区别是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在继承自 ServiceStackController 的 MVC 控制器中,以下三行之间的确切区别是什么?

What's the precise differences between the following three lines in a MVC controller inheriting from ServiceStackController?

(我找不到任何文档中解释的差异)

(I cannot find the difference explained in any documentation)

//A - (default: reload = true)
var session = GetSession(); 

//B
var session = GetSession(false);

//C
var session = SessionAs<IAuthSession>();

推荐答案

GetSession 最好命名为 GetOrCreateSession 因为如果它不存在.它还在 HTTP 请求上下文中存储 Session 的实例,如果 reload:false 将在它存在时返回本地实例:

GetSession is better named GetOrCreateSession as it will either Get a Typed Session or create a new one if it doesn't exist. It also stores the instance of the Session in HTTP Request Context where if reload:false will return the local instance when it exists:

IAuthSession session = GetSession(reload:false);
IAuthSession session = GetSession(reload:true);

如果 reload:true 它将始终从底层 ICacheClient 检索会话.

If reload:true it will always retrieve the Session from the underlying ICacheClient.

SessionAs 总是从 ICacheClient 获取会话,如果不存在则返回一个空实例.它还返回自定义 AuthUserSession 的键入版本:

SessionAs<T> always gets the Session from the ICacheClient and returns an empty instance if it doesn't exist. It also returns a typed version of your Custom AuthUserSession:

CustomUserSession session = SessionAs<CustomUserSession>();

这篇关于从 ServiceStackController 继承的 MVC 控制器中的以下三行之间的确切区别是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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