public void OnServiceMethodDiscovery(ServiceMethodProviderContext <TService> context) { var bindMethodInfo = BindMethodFinder.GetBindMethod(typeof(TService)); // Invoke BindService(ServiceBinderBase, BaseType) if (bindMethodInfo != null) { // The second parameter is always the service base type var serviceParameter = bindMethodInfo.GetParameters()[1]; ServiceDescriptor?serviceDescriptor = null; try { serviceDescriptor = ServiceDescriptorHelpers.GetServiceDescriptor(bindMethodInfo.DeclaringType !); } catch (Exception ex) { Log.ServiceDescriptorError(_logger, typeof(TService), ex); } if (serviceDescriptor != null) { var binder = new HttpApiProviderServiceBinder <TService>( context, new ReflectionServiceInvokerResolver <TService>(serviceParameter.ParameterType), serviceDescriptor, _globalOptions, _serviceOptions, _serviceProvider, _loggerFactory, _serviceActivator, _httpApiOptions); try { bindMethodInfo.Invoke(null, new object?[] { binder, null }); } catch (Exception ex) { throw new InvalidOperationException($"Error binding gRPC service '{typeof(TService).Name}'.", ex); } } } else { Log.BindMethodNotFound(_logger, typeof(TService)); } }
private HttpApiProviderServiceBinder <DynamicService> CreateHttpApiBinder <TRequest, TResponse>( MethodDescriptor methodDescriptor, ServiceMethodProviderContext <DynamicService> context, DynamicServiceInvokerResolver invokerResolver) where TRequest : class, IMessage, new() where TResponse : class, IMessage, new() { var httpApiOptions = _serviceProvider.GetRequiredService <IOptions <GrpcHttpApiOptions> >().Value; var binder = new HttpApiProviderServiceBinder <DynamicService>( context, invokerResolver, methodDescriptor.Service, _serviceProvider.GetRequiredService <IOptions <GrpcServiceOptions> >().Value, _serviceProvider.GetRequiredService <IOptions <GrpcServiceOptions <DynamicService> > >().Value, _serviceProvider, _serviceProvider.GetRequiredService <ILoggerFactory>(), _serviceProvider.GetRequiredService <IGrpcServiceActivator <DynamicService> >(), httpApiOptions); return(binder); }