Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            //Serilog for DI
            services.AddLogging(loggingBuilder =>
                                loggingBuilder.AddSerilog(dispose: true));

            // Конфигурация БД контекста
            string connectionString = Configuration["DbConfig:DbConnectionStrings:Eventador"];

            services.AddDbContext <EventadorDbContext>(options =>
                                                       options.UseNpgsql(connectionString, x =>
            {
                x.MigrationsAssembly("Eventador.Data.Migrations");
                x.SetPostgresVersion(9, 6);
            }));

            // Добавление компрессии на сайт с использованием Gzip
            //
            services.Configure <GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Fastest);
            services.AddResponseCompression(options => { options.EnableForHttps = true; });

            var supportedCultures = new[] { new CultureInfo("ru-RU") };

            services.Configure <RequestLocalizationOptions>(options =>
            {
                options.DefaultRequestCulture = new RequestCulture("ru-RU");
                options.SupportedCultures     = supportedCultures;
                options.SupportedUICultures   = supportedCultures;
            });

            // Для загрузки больших файлов на сервер
            services.Configure <FormOptions>(x =>
            {
                x.ValueLengthLimit         = 10 * 1024 * 1024;
                x.MultipartBodyLengthLimit = 10 * 1024 * 1024;
            });

            RegisterApi(services);
            RegisterServices(services);
            RegisterRepositories(services);

            RegisterAuthentication(services);
            RegisterAuthorization(services);
            RegisterOptions(services);

            RegisterRemoteServices(services);
            RegisterHealthChecks(services);

            RegisterSwagger(services);
            RegisterDistributedCache(services);

            services.AddControllers().AddJsonOptions(options => { JsonSerializer.CreateOptionsByDefault(options); });
        }