Skip to content

Commit

Permalink
Modified the MemoryHost to directly set the IPrincipal instead of usi…
Browse files Browse the repository at this point in the history
…ng a Func
  • Loading branch information
halter73 committed Oct 10, 2012
1 parent 081a77f commit fc0d9d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions SignalR.Hosting.Memory/MemoryHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace SignalR.Hosting.Memory
public class MemoryHost : RoutingHost, IHttpClient, IDisposable
{
private readonly CancellationTokenSource _shutDownToken = new CancellationTokenSource();
private Func<IPrincipal> _userThunk = () => Thread.CurrentPrincipal;

public MemoryHost()
: this(new DefaultDependencyResolver())
Expand All @@ -28,15 +27,13 @@ public MemoryHost(IDependencyResolver resolver)
: base(resolver)
{
resolver.InitializePerformanceCounters(Process.GetCurrentProcess().GetUniqueInstanceName(_shutDownToken.Token), _shutDownToken.Token);

User = Thread.CurrentPrincipal;
}

public string InstanceName { get; set; }

public IPrincipal User
{
get { return _userThunk(); }
set { _userThunk = () => value; }
}
public IPrincipal User { get; set; }

Task<IClientResponse> IHttpClient.GetAsync(string url, Action<IClientRequest> prepareRequest)
{
Expand All @@ -57,7 +54,7 @@ public Task<IClientResponse> ProcessRequest(string url, Action<IClientRequest> p
{
var tcs = new TaskCompletionSource<IClientResponse>();
var clientTokenSource = new CancellationTokenSource();
var request = new Request(uri, clientTokenSource, postData, _userThunk);
var request = new Request(uri, clientTokenSource, postData, User);
prepareRequest(request);

Response response = null;
Expand Down
8 changes: 4 additions & 4 deletions SignalR.Hosting.Memory/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ namespace SignalR.Hosting.Memory
public class Request : IClientRequest, IRequest
{
private readonly CancellationTokenSource _clientTokenSource;
private readonly Func<IPrincipal> _userThunk;

public Request(Uri uri, CancellationTokenSource clientTokenSource, Dictionary<string, string> postData, Func<IPrincipal> userThunk)
public Request(Uri uri, CancellationTokenSource clientTokenSource, Dictionary<string, string> postData, IPrincipal user)
{
Url = uri;
_clientTokenSource = clientTokenSource;
_userThunk = userThunk;
User = user;
Form = new NameValueCollection();
Headers = new NameValueCollection();
ServerVariables = new NameValueCollection();
Expand Down Expand Up @@ -107,7 +106,8 @@ public IRequestCookieCollection Cookies

public IPrincipal User
{
get { return _userThunk(); }
get;
private set;
}

public Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
Expand Down

0 comments on commit fc0d9d5

Please sign in to comment.