Esempio n. 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMemoryCache(x => x.SizeLimit = 1024 * 1024 * 8)
            .AddCors()
            .AddControllers();

            services.AddSingleton <ValidationActionFilter>();

            services.Configure <GzipCompressionProviderOptions>(configureOptions: options => options.Level = CompressionLevel.Fastest)
            .Configure <BrotliCompressionProviderOptions>(configureOptions: options => options.Level       = CompressionLevel.Fastest)
            .AddResponseCompression(configureOptions: options =>
            {
                options.EnableForHttps = true;

                // Explicitly enable Gzip
                options.Providers.Add <BrotliCompressionProvider>();
                options.Providers.Add <GzipCompressionProvider>();

                // Add Custom mime types
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "image/svg+xml" });
            });

            Logging.ConfigureLogging(services: services, environment: this._configuration.Environment);

            services.AddSignalR(this._configuration);

            ApplicationSetup.Configure(services: services, applicationConfiguration: this._configuration);

            // configure authentication
            services.AddSingleton <IEcDsaKeyPairLoader, EcDsaKeyPairLoader>();
            services.AddSingleton <JwtEvents>();

            AuthenticationSetup.Configure(services: services, applicationConfiguration: this._configuration);

            services.AddResponseCaching()
            .AddMvc(setupAction: options => options.Filters.AddService(typeof(ValidationActionFilter)))
            .AddMvcOptions(setupAction: _ =>
            {
                // Note Additional ModelMetadata providers that require DI are enabled elsewhere
            })
            .SetCompatibilityVersion(version: CompatibilityVersion.Latest)
            .AddDataAnnotationsLocalization()
            .AddFluentValidation(configurationExpression: v => v.RegisterValidatorsFromAssemblyContaining <OpenFaucetDtoValidator>())
            .AddJsonOptions(configure: options =>
            {
                JsonSerializerOptions serializerSettings       = options.JsonSerializerOptions;
                serializerSettings.IgnoreNullValues            = true;
                serializerSettings.PropertyNameCaseInsensitive = false;
                serializerSettings.PropertyNamingPolicy        = JsonNamingPolicy.CamelCase;
                serializerSettings.WriteIndented = false;

                JsonConverterSetup.Configure(serializerSettings.Converters);
            });

            services.ConfigureSwaggerServices(version: this._configuration.Version)
            .AddRouting();
        }
        public static async Task Main(string[] args)
        {
            Console.WriteLine(value: "Starting...");
            AppContext.SetSwitch(switchName: "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", isEnabled: true);

            IConfigurationRoot commandLineConfiguration = new ConfigurationBuilder().AddCommandLine(args)
                                                          .Build();

            (int httpPort, int httpsPort, int h2Port) = CommandLineConfiguration.GetServerUrls(commandLineConfiguration);

            using (IWebHost host = CreateWebHost(args: args, httpPort: httpPort, httpsPort: httpsPort, h2Port: h2Port))
            {
                await ApplicationSetup.StartupAsync(serviceProvider : host.Services);

                await host.RunAsync();

                await ApplicationSetup.ShutdownAsync();
            }
        }