| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- using AuthServer.Host.EntityFrameworkCore;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Cors;
- using Microsoft.AspNetCore.DataProtection;
- using Microsoft.Extensions.DependencyInjection;
- using StackExchange.Redis;
- using System;
- using System.Linq;
- using Volo.Abp;
- using Volo.Abp.Account;
- using Volo.Abp.Account.Web;
- using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
- using Volo.Abp.Auditing;
- using Volo.Abp.AuditLogging.EntityFrameworkCore;
- using Volo.Abp.Autofac;
- using Volo.Abp.Data;
- using Volo.Abp.EntityFrameworkCore;
- using Volo.Abp.EntityFrameworkCore.MySQL;
- using Volo.Abp.Identity;
- using Volo.Abp.Identity.EntityFrameworkCore;
- using Volo.Abp.IdentityServer.EntityFrameworkCore;
- using Volo.Abp.Localization;
- using Volo.Abp.Modularity;
- using Volo.Abp.MultiTenancy;
- using Volo.Abp.PermissionManagement.EntityFrameworkCore;
- using Volo.Abp.SettingManagement.EntityFrameworkCore;
- using Volo.Abp.TenantManagement;
- using Volo.Abp.TenantManagement.EntityFrameworkCore;
- using Volo.Abp.Threading;
- namespace AuthServer.Host
- {
- [DependsOn(
- typeof(AbpAutofacModule),
- typeof(AbpPermissionManagementEntityFrameworkCoreModule),
- typeof(AbpAuditLoggingEntityFrameworkCoreModule),
- typeof(AbpSettingManagementEntityFrameworkCoreModule),
- typeof(AbpIdentityEntityFrameworkCoreModule),
- typeof(AbpIdentityApplicationContractsModule),
- typeof(AbpAccountApplicationModule),
- typeof(AbpIdentityServerEntityFrameworkCoreModule),
- typeof(AbpEntityFrameworkCoreMySQLModule),
- typeof(AbpAccountWebIdentityServerModule),
- typeof(AbpAspNetCoreMvcUiBasicThemeModule),
- typeof(AbpTenantManagementEntityFrameworkCoreModule),
- typeof(AbpTenantManagementApplicationContractsModule)
- )]
- public class AuthServerHostModule : AbpModule
- {
- private const string DefaultCorsPolicyName = "Default";
- public override void ConfigureServices(ServiceConfigurationContext context)
- {
- var configuration = context.Services.GetConfiguration();
- context.Services.AddAbpDbContext<AuthServerDbContext>(options =>
- {
- options.AddDefaultRepositories();
- });
- Configure<AbpMultiTenancyOptions>(options =>
- {
- options.IsEnabled = true;
- });
- Configure<AbpDbContextOptions>(options =>
- {
- options.UseMySQL();
- });
- Configure<AbpLocalizationOptions>(options =>
- {
- options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "¼òÌåÖÐÎÄ"));
- });
- context.Services.AddCors(options =>
- {
- options.AddPolicy(DefaultCorsPolicyName,
- builder =>
- {
- builder.WithOrigins(configuration["CorsOrigins"]
- .Split(",", StringSplitOptions.RemoveEmptyEntries)
- .Select(o => o.RemovePostFix("/"))
- .ToArray())
- .WithAbpExposedHeaders()
- .SetIsOriginAllowedToAllowWildcardSubdomains()
- .AllowAnyHeader()
- .AllowAnyMethod()
- .AllowCredentials();
- });
- });
- context.Services.AddSameSiteCookiePolicy();
- //context.Services.AddStackExchangeRedisCache(options =>
- //{
- // options.Configuration = configuration["Redis:Configuration"];
- //});
- Configure<AbpAuditingOptions>(options =>
- {
- options.IsEnabledForGetRequests = true;
- options.ApplicationName = "AuthServer";
- });
- //TODO: ConnectionMultiplexer.Connect call has problem since redis may not be ready when this service has started!
- //var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
- //context.Services.AddDataProtection()
- // .PersistKeysToStackExchangeRedis(redis, "MsDemo-DataProtection-Keys");
- }
- public override void OnApplicationInitialization(ApplicationInitializationContext context)
- {
- var app = context.GetApplicationBuilder();
- app.UseCookiePolicy();
- app.UseCorrelationId();
- app.UseStaticFiles();
- app.UseRouting();
- app.UseCors(DefaultCorsPolicyName);
- app.UseAbpRequestLocalization();
- app.UseAuthentication();
- app.UseMultiTenancy();
- app.UseIdentityServer();
- app.UseAuthorization();
- app.UseAuditing();
- app.UseConfiguredEndpoints();
- AsyncHelper.RunSync(async () =>
- {
- using (var scope = context.ServiceProvider.CreateScope())
- {
- await scope.ServiceProvider
- .GetRequiredService<IDataSeeder>()
- .SeedAsync();
- }
- });
- }
- }
- }
|