diff --git a/src/csharp/Grpc.Core/ClientBase.cs b/src/csharp/Grpc.Core/ClientBase.cs
index e5b398062b2..f5d6ae744f4 100644
--- a/src/csharp/Grpc.Core/ClientBase.cs
+++ b/src/csharp/Grpc.Core/ClientBase.cs
@@ -34,31 +34,76 @@
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using Grpc.Core.Utils;
namespace Grpc.Core
{
///
/// Interceptor for call headers.
///
- /// Header interceptor is no longer to recommented way to perform authentication.
+ /// Header interceptor is no longer the recommended way to perform authentication.
/// For header (initial metadata) based auth such as OAuth2 or JWT access token, use .
///
public delegate void HeaderInterceptor(IMethod method, Metadata metadata);
+ ///
+ /// Generic base class for client-side stubs.
+ ///
+ public abstract class ClientBase : ClientBase
+ where T : ClientBase
+ {
+ ///
+ /// Initializes a new instance of ClientBase class.
+ ///
+ /// The channel to use for remote call invocation.
+ public ClientBase(Channel channel) : base(channel)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of ClientBase class.
+ ///
+ /// The CallInvoker for remote call invocation.
+ public ClientBase(CallInvoker callInvoker) : base(callInvoker)
+ {
+ }
+
+ ///
+ /// Creates a new instance of client from given CallInvoker.
+ ///
+ protected abstract T NewInstance(CallInvoker callInvoker);
+ }
+
///
/// Base class for client-side stubs.
///
public abstract class ClientBase
{
- readonly Channel channel;
+ readonly CallInvoker callInvoker;
///
/// Initializes a new instance of ClientBase class.
///
/// The channel to use for remote call invocation.
- public ClientBase(Channel channel)
+ public ClientBase(Channel channel) : this(new DefaultCallInvoker(channel))
+ {
+ }
+
+ ///
+ /// Initializes a new instance of ClientBase class.
+ ///
+ /// The CallInvoker for remote call invocation.
+ public ClientBase(CallInvoker callInvoker)
{
- this.channel = channel;
+ this.callInvoker = GrpcPreconditions.CheckNotNull(callInvoker);
+ }
+
+ ///
+ /// Gets the call invoker.
+ ///
+ protected CallInvoker CallInvoker
+ {
+ get { return this.callInvoker; }
}
///
@@ -85,17 +130,6 @@ namespace Grpc.Core
set;
}
- ///
- /// Channel associated with this client.
- ///
- public Channel Channel
- {
- get
- {
- return this.channel;
- }
- }
-
///
/// Creates a new call to given method.
///
@@ -104,20 +138,20 @@ namespace Grpc.Core
/// Request message type.
/// Response message type.
/// The call invocation details.
- protected CallInvocationDetails CreateCall(Method method, CallOptions options)
- where TRequest : class
- where TResponse : class
- {
- var interceptor = HeaderInterceptor;
- if (interceptor != null)
- {
- if (options.Headers == null)
- {
- options = options.WithHeaders(new Metadata());
- }
- interceptor(method, options.Headers);
- }
- return new CallInvocationDetails(channel, method, Host, options);
- }
+ //protected CallInvocationDetails CreateCall(Method method, CallOptions options)
+ // where TRequest : class
+ // where TResponse : class
+ //{
+ // var interceptor = HeaderInterceptor;
+ // if (interceptor != null)
+ // {
+ // if (options.Headers == null)
+ // {
+ // options = options.WithHeaders(new Metadata());
+ // }
+ // interceptor(method, options.Headers);
+ // }
+ // return new CallInvocationDetails(channel, method, Host, options);
+ //}
}
}
diff --git a/src/csharp/Grpc.Core/DefaultCallInvoker.cs b/src/csharp/Grpc.Core/DefaultCallInvoker.cs
index 2ec64019acf..8b77651c0cf 100644
--- a/src/csharp/Grpc.Core/DefaultCallInvoker.cs
+++ b/src/csharp/Grpc.Core/DefaultCallInvoker.cs
@@ -44,17 +44,15 @@ namespace Grpc.Core
{
readonly Channel channel;
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Channel to use.
public DefaultCallInvoker(Channel channel)
{
this.channel = GrpcPreconditions.CheckNotNull(channel);
}
- public string Host
- {
- get;
- set;
- }
-
///
/// Invokes a simple remote call in a blocking fashion.
///
@@ -104,11 +102,16 @@ namespace Grpc.Core
return Calls.AsyncDuplexStreamingCall(call);
}
- private CallInvocationDetails CreateCall(Method method, CallOptions options)
+ protected virtual string Host
+ {
+ get { return null; }
+ }
+
+ protected virtual CallInvocationDetails CreateCall(Method method, CallOptions options)
where TRequest : class
where TResponse : class
{
- return new CallInvocationDetails(channel, method, Host, options);
+ return new CallInvocationDetails(channel, method, Host, options);
}
}
}