Ejemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            Measurements.ConfigureMetrics(Environment.EnvironmentName);
            // services.AddSingleton<CountersKeep>();

            var replicatorOptions = Configuration.GetAs <Replicator>();

            var reader = ConfigureReader(
                Ensure.NotEmpty(replicatorOptions.Reader.ConnectionString, "Reader connection string"),
                replicatorOptions.Reader.Protocol,
                replicatorOptions.Reader.PageSize,
                services
                );

            var sink = ConfigureSink(
                Ensure.NotEmpty(replicatorOptions.Sink.ConnectionString, "Sink connection string"),
                replicatorOptions.Sink.Protocol,
                replicatorOptions.Sink.Router,
                services
                );

            var filter = EventFilters.GetFilter(replicatorOptions, reader);

            var prepareOptions = new PreparePipelineOptions(
                filter,
                Transformers.GetTransformer(replicatorOptions),
                1,
                replicatorOptions.Transform?.BufferSize ?? 1
                );

            services.AddSingleton(prepareOptions);
            services.AddSingleton(reader);

            services.AddSingleton(
                new SinkPipeOptions(
                    sink,
                    replicatorOptions.Sink.PartitionCount,
                    replicatorOptions.Sink.BufferSize
                    )
                );

            services.AddSingleton <ICheckpointStore>(
                new FileCheckpointStore(replicatorOptions.Checkpoint.Path, 1000)
                );
            services.AddHostedService <ReplicatorService>();
            services.Configure <HostOptions>(opts => opts.ShutdownTimeout = TimeSpan.FromMinutes(5));
            services.AddSingleton <CountersKeep>();

            services.AddSpaStaticFiles(configuration => configuration.RootPath = "ClientApp/dist");
            services.AddControllers();
            services.AddCors();
        }