private void CreateSimpleServiceStub <TService>(TService serviceImpl, ILightweightMethodBinder methodBinder) where TService : class { var builder = new LightweightServiceStubBuilder <TService>(new RpcServiceOptions <TService> { Serializer = DefaultSerializer }); IRpcServiceDefinitionsProvider serviceDefinitionsProvider = CreateDefinitionsProviderMock(); var hostMock = new Mock <IRpcServerCore>(MockBehavior.Strict); var servicePublisherMock = new Mock <IRpcServicePublisher>(MockBehavior.Strict); var serviceImplProviderMock = new Mock <IRpcServiceActivator>(MockBehavior.Strict); serviceImplProviderMock.Setup(p => p.GetActivatedService <TService>(It.IsAny <IServiceProvider>(), It.IsAny <RpcObjectId>())).Returns(new ActivatedService <TService>(serviceImpl, null)); hostMock.Setup(h => h.ServicePublisher).Returns(servicePublisherMock.Object); hostMock.Setup(h => h.ServiceActivator).Returns(serviceImplProviderMock.Object); hostMock.Setup(h => h.ServiceDefinitionsProvider).Returns(serviceDefinitionsProvider); hostMock.Setup(h => h.CallInterceptors).Returns(ImmutableArrayList <RpcServerCallInterceptor> .Empty); hostMock.Setup(h => h.AllowAutoPublish).Returns(false); hostMock.Setup(h => h.Serializer).Returns(DefaultSerializer); hostMock.Setup(h => h.CustomFaultHandler).Returns((RpcServerFaultHandler)null); hostMock.Setup(p => p.HasContextAccessor).Returns(false); hostMock.Setup(p => p.LoggerFactory).Returns(NullLoggerFactory.Instance); builder.GenerateOperationHandlers(hostMock.Object, methodBinder); }
protected override void AddEventHandlerDefinition <TEventArgs>( RpcEventInfo eventInfo, Func <RpcObjectRequest, IServiceProvider?, IRpcAsyncStreamWriter <TEventArgs>, IRpcContext, ValueTask> beginEventProducer, RpcStub <TService> serviceStub, ILightweightMethodBinder binder) { var beginEventProducerName = $"{eventInfo.FullServiceName}.Begin{eventInfo.Name}"; var methodStub = new LightweightStreamingMethodStub <RpcObjectRequest, TEventArgs>(beginEventProducerName, beginEventProducer, serviceStub.Serializer, null); binder.AddMethod(methodStub); }
protected override void AddCallbackMethodCore <TRequest, TReturn, TResponse>( Func <TService, TRequest, Action <TReturn>, CancellationToken, Task> serviceCaller, Func <TReturn, TResponse>?responseConverter, RpcServerFaultHandler faultHandler, RpcStub <TService> serviceStub, RpcOperationInfo operationInfo, ILightweightMethodBinder binder) { var serializer = serviceStub.Serializer; ValueTask HandleRequest(TRequest request, IServiceProvider?serviceProvider, IRpcAsyncStreamWriter <TResponse> responseWriter, LightweightCallContext context) => serviceStub.CallCallbackMethod(request, serviceProvider, context, responseWriter, serviceCaller, responseConverter, faultHandler, serializer); var methodStub = new LightweightStreamingMethodStub <TRequest, TResponse>(operationInfo.FullName, HandleRequest, serializer, faultHandler); binder.AddMethod(methodStub); }
internal void AddDiscoveryMethods(ILightweightMethodBinder binder) { var getPublishedSingletonsStub = new LightweightMethodStub <RpcDiscoveryRequest, RpcPublishedSingletonsResponse>( ServiceDiscoveryOperations.GetPublishedSingletons, (request, serviceProvider, context) => this.GetPublishedSingletonsAsync(request, serviceProvider, context), this.discoverySerializer, null, false); binder.AddMethod(getPublishedSingletonsStub); var getConnectionInfoStub = new LightweightMethodStub <RpcDiscoveryRequest, RpcConnectionInfoResponse>( ServiceDiscoveryOperations.GetConnectionInfo, (request, serviceProvider, context) => this.GetConnectionInfoAsync(request, context), this.discoverySerializer, null, false); binder.AddMethod(getConnectionInfoStub); }
protected override void AddGenericVoidBlockingMethodCore <TRequest>( Action <TService, TRequest, CancellationToken> serviceCaller, RpcServerFaultHandler faultHandler, RpcStub <TService> serviceStub, RpcOperationInfo operationInfo, ILightweightMethodBinder binder) { var serializer = operationInfo.SerializerOverride ?? serviceStub.Serializer; ValueTask <RpcResponse> HandleRequest(TRequest request, IServiceProvider?serviceProvider, LightweightCallContext context) => serviceStub.CallVoidBlockingMethod(request, serviceProvider, context, serviceCaller, faultHandler, serializer); var methodStub = new LightweightMethodStub <TRequest, RpcResponse>(operationInfo.FullName, HandleRequest, serializer, faultHandler, operationInfo.AllowInlineExecution); binder.AddMethod(methodStub); }