Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Run inversion of control.
            IocSetup.Run(services, Configuration);

            // Run authentication setup.
            AuthenticationSetup.Run(services, Configuration);

            // Add CORS support.
            CorsSetup.Run(services, Configuration);

            // Add http context accessor.
            services.AddHttpContextAccessor();

            // Add app db context.
            AppDbContextSetup.Run(services, Configuration);

            //// some details omitted
            //services.AddIdentityServer()
            //    .AddInMemoryApiResources(Is4Setup.LoadApiResources())
            //    .AddInMemoryIdentityResources(Is4Setup.LoadIdentityResources())
            //    .AddInMemoryClients(Is4Setup.LoadClients())
            //    .AddDeveloperSigningCredential();

            //services.AddAuthentication()
            //    .AddGoogle("Google", options =>
            //    {
            //        options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

            //        options.ClientId = "323676358406-ikvol20relacv3mn5popdi79e5m759pc.apps.googleusercontent.com";
            //        options.ClientSecret = "68pGK3guMhv_bdJKQOznblSi";
            //    })
            //    .AddOpenIdConnect("demoidsrv", "IdentityServer", options =>
            //    {
            //        options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
            //        options.SignOutScheme = IdentityServerConstants.SignoutScheme;

            //        options.Authority = "http://localhost:57547";
            //        options.ClientId = "implicit";
            //        options.ResponseType = "id_token";
            //        options.SaveTokens = true;
            //        options.CallbackPath = new PathString("/signin-idsrv");
            //        options.SignedOutCallbackPath = new PathString("/signout-callback-idsrv");
            //        options.RemoteSignOutPath = new PathString("/signout-idsrv");
            //        options.RequireHttpsMetadata = false;

            //        options.TokenValidationParameters = new TokenValidationParameters
            //        {
            //            NameClaimType = "name",
            //            RoleClaimType = "role"
            //        };
            //    });

            services
            .AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Example #2
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();
        }