Пример #1
0
        /// <summary>
        /// Maps methods from <c>ServerServiceDefinition</c> to server call handlers.
        /// </summary>
        internal static ReadOnlyDictionary <string, IServerCallHandler> GetCallHandlers(this ServerServiceDefinition serviceDefinition)
        {
            var binder = new DefaultServiceBinder();

            serviceDefinition.BindService(binder);
            return(binder.GetCallHandlers());
        }
Пример #2
0
        internal static IReadOnlyList <ServiceDescriptor> GetDescriptors(this ServerServiceDefinition serviceDefinition)
        {
            var binder = new DefaultServiceBinder();

            serviceDefinition.BindService(binder);
            return(binder.GetDescriptors());
        }
Пример #3
0
        private static IEnumerable <string> GetServiceDescriptorIdentities(ServerServiceDefinition serviceDefinition)
        {
            var binder = new DescriptorOnlyServiceBinder();

            serviceDefinition.BindService(binder);
            return(binder.GetDescriptors()
                   .Select(service => service.File.GetIdentity()));
        }
        /// <summary>
        /// Returns a <see cref="Grpc.Core.ServerServiceDefinition" /> instance that
        /// intercepts incoming calls to the underlying service handler through the given interceptor.
        /// </summary>
        /// <param name="serverServiceDefinition">The <see cref="Grpc.Core.ServerServiceDefinition" /> instance to register interceptors on.</param>
        /// <param name="interceptor">The interceptor to intercept the incoming invocations with.</param>
        /// <remarks>
        /// Multiple interceptors can be added on top of each other by calling
        /// "serverServiceDefinition.Intercept(a, b, c)".  The order of invocation will be "a", "b", and then "c".
        /// Interceptors can be later added to an existing intercepted service definition, effectively
        /// building a chain like "serverServiceDefinition.Intercept(c).Intercept(b).Intercept(a)".  Note that
        /// in this case, the last interceptor added will be the first to take control.
        /// </remarks>
        public static ServerServiceDefinition Intercept(this ServerServiceDefinition serverServiceDefinition, Interceptor interceptor)
        {
            GrpcPreconditions.CheckNotNull(serverServiceDefinition, nameof(serverServiceDefinition));
            GrpcPreconditions.CheckNotNull(interceptor, nameof(interceptor));

            var binder = new InterceptingServiceBinder(interceptor);

            serverServiceDefinition.BindService(binder);
            return(binder.GetInterceptedServerServiceDefinition());
        }