【发布时间】:2015-10-28 11:32:23
【问题描述】:
我看过:https://github.com/ServiceStack/ServiceStack/wiki/Sessions#saving-outside-a-service
我仍然不明白,如果我有一个我想从 MVC 控制器和 servicestack 服务调用的类方法,我如何保存会话。是否可以不传递服务引用?...以下是我的用例:
public async Task<User> StoreAsync(User user, CustomUserSession session)
{
using (var db = DbFactory.Open())
{
await db.SaveAsync(user).ConfigureAwait(false);
}
if (session != null)
{
session.EmailConfirmed = user.EmailConfirmed;
session.ProfileImageUrl = user.ProfileImageUrl;
session.ThumbnailProfileImageUrl = user.ThumbnailProfileImageUrl;
//Following only works if I am calling the method from an MVC controller
IHttpRequest httpReq = HttpContext.Current.ToRequest();
httpReq.SaveSession(session);
//What if I call this method from a servicestack service,
//I don't really want to inject the service as an optional parameter
}
return user;
}
【问题讨论】:
标签: asp.net-mvc session servicestack