1 #region Copyright notice and license
3 // Copyright 2019 The gRPC Authors
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 using Grpc.Core.Utils;
25 /// Base class for lightweight client-side stubs.
26 /// All calls are invoked via a <c>CallInvoker</c>.
27 /// Lite client stubs have no configuration knobs, all configuration
28 /// is provided by decorating the call invoker.
29 /// Note: experimental API that can change or be removed without any prior notice.
31 public abstract class LiteClientBase
33 readonly CallInvoker callInvoker;
36 /// Initializes a new instance of <c>LiteClientBase</c> class that
37 /// throws <c>NotImplementedException</c> upon invocation of any RPC.
38 /// This constructor is only provided to allow creation of test doubles
39 /// for client classes (e.g. mocking requires a parameterless constructor).
41 protected LiteClientBase() : this(new UnimplementedCallInvoker())
46 /// Initializes a new instance of <c>ClientBase</c> class.
48 /// <param name="callInvoker">The <c>CallInvoker</c> for remote call invocation.</param>
49 public LiteClientBase(CallInvoker callInvoker)
51 this.callInvoker = GrpcPreconditions.CheckNotNull(callInvoker, nameof(callInvoker));
55 /// Gets the call invoker.
57 protected CallInvoker CallInvoker
59 get { return this.callInvoker; }
63 /// Call invoker that throws <c>NotImplementedException</c> for all requests.
65 private class UnimplementedCallInvoker : CallInvoker
67 public UnimplementedCallInvoker()
71 public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
73 throw new NotImplementedException();
76 public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
78 throw new NotImplementedException();
81 public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
83 throw new NotImplementedException();
86 public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
88 throw new NotImplementedException();
91 public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
93 throw new NotImplementedException();