Esempio n. 1
0
        public GrpcTestEventHost(ApplicationConfiguration configuration)
        {
            _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _builder       = new HostBuilder();

            _builder.ConfigureServices(services =>
            {
                services.AddGrpc();
            });
            var stuff = _builder.ConfigureServices((hostContext, services) =>
            {
                // setup the reflection support for service discovery
                var reflectionService = new ReflectionServiceImpl(TestEvent.Descriptor, ServerReflection.Descriptor);
                var testEventService  = new TestEventService(_configuration);
                testEventService.TestEventReceived += TestEventService_TestEventReceived;
                // create a Grpc server
                var server = new Server
                {
                    Services = { TestEvent.BindService(testEventService), ServerReflection.BindService(reflectionService) },
                    Ports    = { new ServerPort(GrpcServer, _configuration.Port, ServerCredentials.Insecure) },
                };
                var gprcHostedService = new GrpcHostedService(server);
                services.AddSingleton(server);
                services.AddSingleton(gprcHostedService);
                services.AddSingleton <IHostedService, GrpcHostedService>(serviceProvider => gprcHostedService);
                _serviceProvider = services.BuildServiceProvider();
            });
        }