Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddLogging(configure => configure.AddConsole());
            services.AddSingleton <AppContainer>();

            services.AddSingleton(_ => new StorageOptions(Configuration["Storage"]));

            services.AddMediatR(typeof(Startup).Assembly);
            services.AddValidators(typeof(Startup));
            services.AddBehaviorsForRequest <IDriveRequest>(typeof(Startup));
            services.AddErrorHandling(typeof(Startup));

            services.AddControllers();
            services.AddHttpContextAccessor();

            services.AddHealthChecks()
            .AddCheck <LivenessCheck>("liveness", tags: new List <string> {
                "liveness"
            })
            .AddCheck <ReadinessCheck>("readiness", tags: new List <string> {
                "readiness"
            });

            services.AddSingleton(_ =>
                                  new ValuesContainer(Configuration["SecretValue"], Configuration["NotSecretValue"]));

            services.AddSingleton(sp =>
            {
                var reflectionServiceImpl = new ReflectionServiceImpl(FileService.Descriptor, ServerReflection.Descriptor);
                var server = new Server
                {
                    Services =
                    {
                        FileService.BindService(new Grpc.FileService(sp.GetService <StorageOptions>())),
                        ServerReflection.BindService(reflectionServiceImpl)
                    },
                    Ports = { new ServerPort("localhost", 3000, ServerCredentials.Insecure) },
                };
                return(server);
            });

            services.AddHostedService <GrpcHostedService>();
        }
Example #2
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            return(Task.Factory.StartNew(() =>
            {
                var channelOptions = new List <ChannelOption>()
                {
                    new ChannelOption(ChannelOptions.MaxReceiveMessageLength, int.MaxValue),
                    new ChannelOption(ChannelOptions.MaxSendMessageLength, int.MaxValue)
                };

                _grpcServer = new Server(channelOptions)
                {
                    Services = { SchedulerService.BindService(_schedulerServiceBase), FileService.BindService(_fileServiceBase) },
                    Ports = { new ServerPort(_config.Host, _config.Port, ServerCredentials.Insecure) }
                };

                _grpcServer.Start();
            }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current));
        }