-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created ISession with SessionFactory provider using ICacheClient.
Can now share the same session between MVC and ServiceStack with ISession Can now RequestContext.Get<IHttpResponse>() Can now Filter = (req, res, dto) => req.TryResolve<IDependency>();
- Loading branch information
Showing
47 changed files
with
359 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,31 @@ | |||
namespace ServiceStack.CacheAccess | |||
{ | |||
/// <summary> | |||
/// A Users Session | |||
/// </summary> | |||
public interface ISession | |||
{ | |||
/// <summary> | |||
/// Store any object at key | |||
/// </summary> | |||
/// <param name="key"></param> | |||
/// <returns></returns> | |||
object this[string key] { get; set; } | |||
|
|||
/// <summary> | |||
/// Set a typed value at key | |||
/// </summary> | |||
/// <typeparam name="T"></typeparam> | |||
/// <param name="key"></param> | |||
/// <param name="value"></param> | |||
void Set<T>(string key, T value); | |||
|
|||
/// <summary> | |||
/// Get a typed value at key | |||
/// </summary> | |||
/// <typeparam name="T"></typeparam> | |||
/// <param name="key"></param> | |||
/// <returns></returns> | |||
T Get<T>(string key); | |||
} | |||
} |
18 changes: 18 additions & 0 deletions
18
src/ServiceStack.Interfaces/CacheAccess/ISessionFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
using ServiceStack.ServiceHost; | |||
|
|||
namespace ServiceStack.CacheAccess | |||
{ | |||
/// <summary> | |||
/// Retrieves a User Session | |||
/// </summary> | |||
public interface ISessionFactory | |||
{ | |||
/// <summary> | |||
/// Gets the session for this request, creates one if it doesn't exist. | |||
/// </summary> | |||
/// <param name="httpReq"></param> | |||
/// <param name="httpRes"></param> | |||
/// <returns></returns> | |||
ISession GetOrCreateSession(IHttpRequest httpReq, IHttpResponse httpRes); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,61 @@ | |||
using System; | |||
using ServiceStack.CacheAccess; | |||
using ServiceStack.ServiceHost; | |||
using ServiceStack.Text; | |||
using ServiceStack.Text.Common; | |||
|
|||
namespace ServiceStack.ServiceInterface | |||
{ | |||
public class SessionFactory : ISessionFactory | |||
{ | |||
private readonly ICacheClient cacheClient; | |||
|
|||
public SessionFactory(ICacheClient cacheClient) | |||
{ | |||
this.cacheClient = cacheClient; | |||
} | |||
|
|||
public class SessionCacheClient : ISession | |||
{ | |||
private readonly ICacheClient cacheClient; | |||
private string prefixNs; | |||
|
|||
public SessionCacheClient(ICacheClient cacheClient, string sessionId) | |||
{ | |||
this.cacheClient = cacheClient; | |||
this.prefixNs = "sess:" + sessionId + ":"; | |||
} | |||
|
|||
public object this[string key] | |||
{ | |||
get | |||
{ | |||
return cacheClient.Get<object>(this.prefixNs + key); | |||
} | |||
set | |||
{ | |||
JsWriter.WriteDynamic(() => | |||
cacheClient.Set(this.prefixNs + key, value)); | |||
} | |||
} | |||
|
|||
public void Set<T>(string key, T value) | |||
{ | |||
cacheClient.Set(this.prefixNs + key, value); | |||
} | |||
|
|||
public T Get<T>(string key) | |||
{ | |||
return cacheClient.Get<T>(this.prefixNs + key); | |||
} | |||
} | |||
|
|||
public ISession GetOrCreateSession(IHttpRequest httpReq, IHttpResponse httpRes) | |||
{ | |||
var sessionId = httpReq.GetCookieValue(SessionFeature.PermanentSessionId) | |||
?? httpRes.CreatePermanentSessionId(httpReq); | |||
|
|||
return new SessionCacheClient(cacheClient, sessionId); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.