Esempio n. 1
0
        /// <summary>
        /// 指定された型に対するサービス定義を生成します。
        /// </summary>
        /// <param name="serviceName">サービス名</param>
        /// <param name="serviceType">サービスの型</param>
        /// <param name="serviceInstance">サービスインスタンス</param>
        /// <param name="settings">動作設定</param>
        /// <returns></returns>
        public ServerServiceDefinition BuildService(string serviceName, Type serviceType, object serviceInstance, GrpcServiceBuilderSettings settings)
        {
            settings = settings ?? new GrpcServiceBuilderSettings();

            ServerServiceDefinition.Builder builder = ServerServiceDefinition.CreateBuilder();

            Type implType = serviceInstance.GetType();

            IList <IGrpcServerMethodInvokingInterceptor> classInvokingInterceptors = GetInvokingInterceptors(implType);
            IList <IGrpcServerMethodInvokedInterceptor>  classInvokedInterceptors  = GetInvokedInterceptors(implType);

            foreach (GrpcMethodHandlerInfo method in GrpcReflection.EnumerateServiceMethods(implType))
            {
                IList <IGrpcServerMethodInvokingInterceptor> methodInvokingInterceptors = GetInvokingInterceptors(method.Handler);
                IList <IGrpcServerMethodInvokedInterceptor>  methodInvokedInterceptors  = GetInvokedInterceptors(method.Handler);

                MethodBuildContext context = new MethodBuildContext(serviceName, serviceType, serviceInstance, method.MethodType, method.RequestType, method.ResponseType, method.Handler, settings
                                                                    , Sort <IGrpcServerMethodInvokingInterceptor>(CompareInterceptor, new IEnumerable <IGrpcServerMethodInvokingInterceptor>[] { settings.InvokingInterceptors, classInvokingInterceptors, methodInvokingInterceptors })
                                                                    , Sort <IGrpcServerMethodInvokedInterceptor>(CompareInterceptor, new IEnumerable <IGrpcServerMethodInvokedInterceptor>[] { settings.InvokedInterceptors, classInvokedInterceptors, methodInvokedInterceptors })
                                                                    , Sort <IGrpcServerMethodExceptionHandler>(CompareInterceptor, new IEnumerable <IGrpcServerMethodExceptionHandler>[] { settings.ExceptionHandlers })
                                                                    );

                AddServiceMethod(builder, context);
            }

            return(builder.Build());
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceName"></param>
        /// <param name="serviceType"></param>
        /// <param name="marshallerFactory"></param>
        /// <returns></returns>
        public static IList <GrpcServiceMethod> GetGrpcMethods(string serviceName, Type serviceType, IGrpcMarshallerFactory marshallerFactory)
        {
            List <GrpcServiceMethod> methods = new List <GrpcServiceMethod>();

            foreach (GrpcMethodHandlerInfo handler in GrpcReflection.EnumerateServiceMethods(serviceType))
            {
                IMethod method = GrpcReflection.CreateMethod(serviceName, handler, marshallerFactory);

                methods.Add(new GrpcServiceMethod(method, handler.RequestType, handler.ResponseType));
            }

            return(methods);
        }