コード例 #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient(p => new HouseholdConfiguration(p.GetService <IConfiguration>()));
            services.AddTransient(p => new ProductsImportHandler(p.GetService <ILogger <ProductsImportHandler> >()));

            services.AddDbContext <HouseholdDbContext>(
                o => DatabaseSystemFeatures.DefineSqlServer(o, HouseholdConfiguration));

            services.AddDefaultIdentity <ApplicationUser>()
            .AddEntityFrameworkStores <HouseholdDbContext>();
            services.Configure <IdentityOptions>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
            });

            var key = CertificateLoader.LoadRsaSecurityKey(HouseholdConfiguration.KeyPath);

            services.AddIdentityServer()
            .AddAspNetIdentity <ApplicationUser>()
            .AddOperationalStore <HouseholdDbContext>()
            .AddIdentityResources()
            .AddSigningCredential(key, IdentityServerConstants.RsaSigningAlgorithm.PS512)
            .AddApiResources()
            .AddClients();

            services.AddAuthentication()
            .AddIdentityServerJwt();

            services.AddCors();
            services.AddControllersWithViews();

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; });

            services.AddRazorPages();

            services.AddMvc().AddRazorPagesOptions(o => { o.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute()); });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title   = "Apishka",
                    Version = "v1"
                });
            });

            services.AddAutoMapper(typeof(Startup));

            services.Configure <KestrelServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });
        }