using System; using System.Collections.Generic; namespace Google.GRPC.Core { public class ServerServiceDefinition { readonly string serviceName; // TODO: we would need an immutable dictionary here... readonly Dictionary callHandlers; private ServerServiceDefinition(string serviceName, Dictionary callHandlers) { this.serviceName = serviceName; this.callHandlers = new Dictionary(callHandlers); } internal Dictionary CallHandlers { get { return this.callHandlers; } } public static Builder CreateBuilder(String serviceName) { return new Builder(serviceName); } public class Builder { readonly string serviceName; readonly Dictionary callHandlers = new Dictionary(); public Builder(string serviceName) { this.serviceName = serviceName; } public Builder AddMethod( Method method, UnaryRequestServerMethod handler) { callHandlers.Add(method.Name, ServerCalls.UnaryRequestCall(method, handler)); return this; } public Builder AddMethod( Method method, StreamingRequestServerMethod handler) { callHandlers.Add(method.Name, ServerCalls.StreamingRequestCall(method, handler)); return this; } public ServerServiceDefinition Build() { return new ServerServiceDefinition(serviceName, callHandlers); } } } }