Exemple #1
0
        internal static void CreateUnimplementedEndpoints(
            IEndpointRouteBuilder endpointRouteBuilder,
            ServiceMethodsRegistry serviceMethodsRegistry,
            ServerCallHandlerFactory <TService> serverCallHandlerFactory,
            List <MethodModel> serviceMethods)
        {
            // Return UNIMPLEMENTED status for missing service:
            // - /{service}/{method} + content-type header = grpc/application
            if (!serverCallHandlerFactory.IgnoreUnknownServices && serviceMethodsRegistry.Methods.Count == 0)
            {
                // Only one unimplemented service endpoint is needed for the application
                CreateUnimplementedEndpoint(endpointRouteBuilder, "{unimplementedService}/{unimplementedMethod}", "Unimplemented service", serverCallHandlerFactory.CreateUnimplementedService());
            }

            // Return UNIMPLEMENTED status for missing method:
            // - /Package.Service/{method} + content-type header = grpc/application
            if (!serverCallHandlerFactory.IgnoreUnknownMethods)
            {
                var serviceNames = serviceMethods.Select(m => m.Method.ServiceName).Distinct();

                // Typically there should be one service name for a type
                // In case the bind method sets up multiple services in one call we'll loop over them
                foreach (var serviceName in serviceNames)
                {
                    if (serviceMethodsRegistry.Methods.Any(m => string.Equals(m.Method.ServiceName, serviceName, StringComparison.Ordinal)))
                    {
                        // Only one unimplemented method endpoint is need for the service
                        continue;
                    }

                    CreateUnimplementedEndpoint(endpointRouteBuilder, serviceName + "/{unimplementedMethod}", $"Unimplemented method for {serviceName}", serverCallHandlerFactory.CreateUnimplementedMethod());
                }
            }
        }
Exemple #2
0
 public ServiceRouteBuilder(
     IEnumerable <IServiceMethodProvider <TService> > serviceMethodProviders,
     ServerCallHandlerFactory <TService> serverCallHandlerFactory,
     ServiceMethodsRegistry serviceMethodsRegistry,
     ILoggerFactory loggerFactory)
 {
     _serviceMethodProviders   = serviceMethodProviders.ToList();
     _serverCallHandlerFactory = serverCallHandlerFactory;
     _serviceMethodsRegistry   = serviceMethodsRegistry;
     _logger = loggerFactory.CreateLogger <ServiceRouteBuilder <TService> >();
 }