ServiceStack服务未在我的CustomUserSession中自动连接
本文关键字:连接 CustomUserSession 我的 服务 ServiceStack | 更新日期: 2023-09-27 18:20:52
public class SteamUserSession : AuthUserSession
{
public UserService UserService { get; set; } //Should be autowired
public long SteamID { get; private set; }
public User CurrentUser { get; private set; }
public Player SteamProfile { get; private set; }
public List<SteamGame> OwnedApps { get; private set; }
public override void OnAuthenticated(
IServiceBase authService,
IAuthSession session,
IOAuthTokens tokens,
Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
// access servicestack user server and load properies for session here
CurrentUser = (User)UserService.Get(new GetUser(SteamID));
}
}
AuthUserSession
只是一个从数据存储中持久化和检索的模型,即它不是从IOC解析(并自动连接)的服务/过滤器等或控制器。
相反,您可以使用传入的authService
从IOC检索依赖项,例如:
public override void OnAuthenticated(
IServiceBase authService,
IAuthSession session,
IOAuthTokens tokens,
Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
// access servicestack user server and load properies for session here
var userService = authService.TryResolve<UserService>();
CurrentUser = (User)userService.Get(new GetUser(SteamID));
}