using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Acme.BookStore.BookManagement.MultiTenancy; using StackExchange.Redis; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.Swagger; using Volo.Abp; using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.Auditing; using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.Autofac; using Volo.Abp.Caching; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.SqlServer; 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.PermissionManagement; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.PermissionManagement.HttpApi; using Volo.Abp.PermissionManagement.Identity; using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.Threading; using Volo.Abp.UI.Navigation.Urls; namespace Acme.BookStore.BookManagement { [DependsOn( typeof(AbpAccountWebIdentityServerModule), typeof(AbpAspNetCoreMultiTenancyModule), typeof(AbpAspNetCoreMvcModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAuditLoggingEntityFrameworkCoreModule), typeof(AbpAutofacModule), typeof(AbpEntityFrameworkCoreSqlServerModule), typeof(AbpIdentityEntityFrameworkCoreModule), typeof(AbpIdentityApplicationModule), typeof(AbpIdentityHttpApiModule), typeof(AbpIdentityServerEntityFrameworkCoreModule), typeof(AbpPermissionManagementDomainIdentityModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpPermissionManagementApplicationModule), typeof(AbpPermissionManagementHttpApiModule), typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(AbpTenantManagementEntityFrameworkCoreModule), typeof(AbpTenantManagementApplicationModule), typeof(AbpTenantManagementHttpApiModule), typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(BookManagementApplicationContractsModule) )] public class BookManagementIdentityServerModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = context.Services.GetConfiguration(); Configure(options => { options.UseSqlServer(); }); context.Services.AddSwaggerGen( options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "BookManagement API", Version = "v1" }); options.DocInclusionPredicate((docName, description) => true); options.CustomSchemaIds(type => type.FullName); }); Configure(options => { options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština")); options.Languages.Add(new LanguageInfo("en", "en", "English")); options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português")); options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe")); options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); }); Configure(options => { //options.IsEnabledForGetRequests = true; options.ApplicationName = "AuthServer"; }); Configure(options => { options.Applications["MVC"].RootUrl = configuration["AppSelfUrl"]; }); context.Services.AddAuthentication() .AddIdentityServerAuthentication(options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = false; options.ApiName = configuration["AuthServer:ApiName"]; }); Configure(options => { options.KeyPrefix = "BookManagement:"; }); context.Services.AddStackExchangeRedisCache(options => { options.Configuration = configuration["Redis:Configuration"]; }); if (!hostingEnvironment.IsDevelopment()) { var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); context.Services .AddDataProtection() .PersistKeysToStackExchangeRedis(redis, "BookManagement-Protection-Keys"); } } public override void OnApplicationInitialization(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); if (!context.GetEnvironment().IsDevelopment()) { app.UseHsts(); } app.UseHttpsRedirection(); app.UseCorrelationId(); app.UseVirtualFiles(); app.UseRouting(); app.UseAuthentication(); app.UseJwtTokenMiddleware(); if (MultiTenancyConsts.IsEnabled) { app.UseMultiTenancy(); } app.UseIdentityServer(); app.UseAuthorization(); app.UseAbpRequestLocalization(); app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support APP API"); }); app.UseAuditing(); app.UseMvcWithDefaultRouteAndArea(); SeedData(context); } private void SeedData(ApplicationInitializationContext context) { AsyncHelper.RunSync(async () => { using (var scope = context.ServiceProvider.CreateScope()) { await scope.ServiceProvider .GetRequiredService() .SeedAsync(); } }); } } }