コード例 #1
0
        private static async Task Main(string[] args)
        {
            SetLogger(new ConsoleLogger());

            var service = new CacheServiceImpl(Logger);
            var server  = new Grpc.Core.Server
            {
                Ports    = { { "localhost", 5000, Credentials.CreateSslServerCredentials() } },
                Services =
                {
                    CacheService.BindService(service)
                    .Intercept(new CorrelationIdInterceptor())
                    .Intercept(new JwtValidationInterceptor(Logger))
                    .Intercept(new LoggingInterceptor(Logger)),

                    ServerServiceDefinition.CreateBuilder()
                    .AddMethod(Descriptors.GetAsJsonMethod, service.GetAsJson)
                    .AddMethod(Descriptors.SetAsJsonMethod, service.SetAsJson)
                    .Build()
                    .Intercept(new CorrelationIdInterceptor())
                    .Intercept(new JwtValidationInterceptor(Logger))
                    .Intercept(new LoggingInterceptor(Logger))
                }
            };

            server.Start();

            var webHost = new WebHostBuilder()
                          .UseKestrel()
                          .UseStartup <Startup>()
                          .UseUrls("http://localhost:60000")
                          .Build();

            await webHost.RunAsync();
        }