public RpcServiceInfo?GetRegisteredServiceInfo(Type serviceType) { if (this.registeredServiceTypes.TryGetValue(serviceType, out var registration)) { return(RpcBuilderUtil.GetServiceInfoFromType(serviceType, registration.ImplementationType)); } return(null); }
public IReadOnlyList <object> GenerateMethodStubs <TService>(IRpcServerCore rpcServer) where TService : class { var builder = new GrpcServiceStubBuilder <TService>(RpcBuilderUtil.GetServiceInfoFromType(typeof(TService)), null); var binder = new TestGrpcMethodBinder(); builder.GenerateOperationHandlers(rpcServer, binder); return(binder.stubs); }
/// <summary> /// Adds service specific options to an <see cref="IRpcServerBuilder"/>. /// </summary> /// <typeparam name="TService">The service type to configure.</typeparam> /// <param name="rpcBuilder">The <see cref="IRpcServerBuilder"/>.</param> /// <param name="configure">A callback to configure the service options.</param> /// <returns>The same instance of the <see cref="IRpcServerBuilder"/> for chaining.</returns> public static IRpcServerBuilder AddServiceOptions <TService>(this IRpcServerBuilder rpcBuilder, Action <RpcServiceOptions <TService> > configure) where TService : class { if (rpcBuilder == null) { throw new ArgumentNullException(nameof(rpcBuilder)); } // GetServiceInfoFromType will throw if TService is not an RPC service (replace with an IsRpcService method) RpcBuilderUtil.GetServiceInfoFromType(typeof(TService)); rpcBuilder.Services.Configure(configure); Rpc.ServiceCollectionExtensions.NotifyServiceRegistered <TService>(rpcBuilder.Services); return(rpcBuilder); }
/// <summary> /// Gets all services that should be implemented by the proxy, based on information about the requested <typeparamref name="TService"/>, /// the implemented services on the server side, and registered proxy types. /// </summary> /// <typeparam name="TService"></typeparam> /// <param name="implementedServices"></param> /// <returns></returns> private static List <RpcServiceInfo> GetAllServices <TService>( IReadOnlyCollection <string>?implementedServices, IReadOnlyDictionary <string, ImmutableArray <Type> >?knownServiceTypes) { var interfaceServices = RpcBuilderUtil.GetAllServices(typeof(TService), RpcServiceDefinitionSide.Client, false); if (implementedServices?.Count > 0) { // We have information about implemented services on the server side. // Make sure that the interfaceServices are actually implemented foreach (var interfaceService in interfaceServices) { if (!implementedServices.Any(s => s == interfaceService.FullName)) { throw new RpcServiceUnavailableException($"Service '{interfaceService.FullName}' is not implemented."); } } // And add all known service interfaces. if (knownServiceTypes != null) { foreach (var implementedService in implementedServices) { if (knownServiceTypes.TryGetValue(implementedService, out var knownTypes)) { foreach (var serviceType in knownTypes) { if (interfaceServices.Find(s => s.Type.Equals(serviceType)) == null) { var serviceInfo = RpcBuilderUtil.GetServiceInfoFromType(serviceType); interfaceServices.Add(serviceInfo); // serviceInfo is not null when throwOnError is true. } } } } } } return(interfaceServices); }
public GrpcServiceStubBuilder(RpcServiceOptions <TService>?options) : this(RpcBuilderUtil.GetServiceInfoFromType(typeof(TService)), options) { }