Make ServerCallContext.UserData a virtual property

pull/18086/head
Christopher Warrington 6 years ago
parent 4645f0d299
commit 3421c9c4f9
  1. 17
      src/csharp/Grpc.Core.Api/ServerCallContext.cs
  2. 15
      src/csharp/Grpc.Core.Testing/TestServerCallContext.cs
  3. 15
      src/csharp/Grpc.Core/Internal/DefaultServerCallContext.cs

@ -28,6 +28,8 @@ namespace Grpc.Core
/// </summary>
public abstract class ServerCallContext
{
private Dictionary<object, object> userState;
/// <summary>
/// Creates a new instance of <c>ServerCallContext</c>.
/// </summary>
@ -118,7 +120,18 @@ namespace Grpc.Core
/// Gets a dictionary that can be used by the various interceptors and handlers of this
/// call to store arbitrary state.
/// </summary>
public IDictionary<object, object> UserSate => UserStateCore;
public virtual IDictionary<object, object> UserSate
{
get
{
if (userState == null)
{
userState = new Dictionary<object, object>();
}
return userState;
}
}
/// <summary>Provides implementation of a non-virtual public member.</summary>
protected abstract Task WriteResponseHeadersAsyncCore(Metadata responseHeaders);
@ -144,7 +157,5 @@ namespace Grpc.Core
protected abstract WriteOptions WriteOptionsCore { get; set; }
/// <summary>Provides implementation of a non-virtual public member.</summary>
protected abstract AuthContext AuthContextCore { get; }
/// <summary>Provides implementation of a non-virtual public member.</summary>
protected abstract IDictionary<object, object> UserStateCore { get; }
}
}

@ -17,7 +17,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@ -51,7 +50,6 @@ namespace Grpc.Core.Testing
private Status status;
private readonly string peer;
private readonly AuthContext authContext;
private Dictionary<object, object> userState;
private readonly ContextPropagationToken contextPropagationToken;
private readonly Func<Metadata, Task> writeHeadersFunc;
private readonly Func<WriteOptions> writeOptionsGetter;
@ -95,19 +93,6 @@ namespace Grpc.Core.Testing
protected override AuthContext AuthContextCore => authContext;
protected override IDictionary<object, object> UserStateCore
{
get
{
if (userState == null)
{
userState = new Dictionary<object, object>();
}
return userState;
}
}
protected override ContextPropagationToken CreatePropagationTokenCore(ContextPropagationOptions options)
{
return contextPropagationToken;

@ -17,7 +17,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@ -40,7 +39,6 @@ namespace Grpc.Core
private Status status;
private readonly IServerResponseStream serverResponseStream;
private readonly Lazy<AuthContext> authContext;
private Dictionary<object, object> userState;
/// <summary>
/// Creates a new instance of <c>ServerCallContext</c>.
@ -101,19 +99,6 @@ namespace Grpc.Core
protected override AuthContext AuthContextCore => authContext.Value;
protected override IDictionary<object, object> UserStateCore
{
get
{
if (userState == null)
{
userState = new Dictionary<object, object>();
}
return userState;
}
}
private AuthContext GetAuthContextEager()
{
using (var authContextNative = callHandle.GetAuthContext())

Loading…
Cancel
Save