using System; using System.IO; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; using BookStore.Blazor.Menus; using BookStore.EntityFrameworkCore; using BookStore.Localization; using BookStore.MultiTenancy; using Lsw.Abp.AspnetCore.Components.Server.AntDesignTheme.Bundling; using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Routing; using Lsw.Abp.IdentityManagement.Blazor.Server.AntDesignUI; using Lsw.Abp.TenantManagement.Blazor.Server.AntDesignUI; using Volo.Abp; using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling; using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Lsw.Abp.SettingManagement.Blazor.AntDesignUI; using Lsw.Abp.SettingManagement.Blazor.Server.AntDesignUI; using Volo.Abp.Swashbuckle; using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.VirtualFileSystem; namespace BookStore.Blazor; [DependsOn( typeof(BookStoreApplicationModule), typeof(BookStoreEntityFrameworkCoreModule), typeof(BookStoreHttpApiModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAutofacModule), typeof(AbpSwashbuckleModule), typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(AbpAspNetCoreSerilogModule), typeof(AbpAccountWebIdentityServerModule), typeof(AbpIdentityBlazorServerAntDesignModule), typeof(AbpTenantManagementBlazorServerAntDesignModule), typeof(AbpSettingManagementBlazorServerAntDesignModule) )] public class BookStoreBlazorModule : AbpModule { public override void PreConfigureServices(ServiceConfigurationContext context) { context.Services.PreConfigure(options => { options.AddAssemblyResource( typeof(BookStoreResource), typeof(BookStoreDomainModule).Assembly, typeof(BookStoreDomainSharedModule).Assembly, typeof(BookStoreApplicationModule).Assembly, typeof(BookStoreApplicationContractsModule).Assembly, typeof(BookStoreBlazorModule).Assembly ); }); } public override void ConfigureServices(ServiceConfigurationContext context) { var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = context.Services.GetConfiguration(); ConfigureUrls(configuration); ConfigureBundles(); ConfigureAuthentication(context, configuration); ConfigureAutoMapper(); ConfigureLocalizationServices(); ConfigureSwaggerServices(context.Services); ConfigureAutoApiControllers(); ConfigureRouter(context); ConfigureMenu(context); } private void ConfigureUrls(IConfiguration configuration) { Configure(options => { options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; options.RedirectAllowedUrls.AddRange(configuration["App:RedirectAllowedUrls"].Split(',')); }); } private void ConfigureBundles() { Configure(options => { // MVC UI options.StyleBundles.Configure( BasicThemeBundles.Styles.Global, bundle => { bundle.AddFiles("/global-styles.css"); } ); //BLAZOR UI options.StyleBundles.Configure( BlazorAntDesignThemeBundles.Styles.Global, bundle => { bundle.AddFiles("/blazor-global-styles.css"); //You can remove the following line if you don't use Blazor CSS isolation for components bundle.AddFiles("/BookStore.BlazorServer.styles.css"); } ); }); } private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) { context.Services.AddAuthentication() .AddJwtBearer(options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); options.Audience = "BookStore"; }); } private void ConfigureLocalizationServices() { Configure(options => { options.Languages.Add(new LanguageInfo("ar", "ar", "العربية")); options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština")); options.Languages.Add(new LanguageInfo("en", "en", "English")); options.Languages.Add(new LanguageInfo("en-GB", "en-GB", "English (UK)")); options.Languages.Add(new LanguageInfo("hu", "hu", "Magyar")); options.Languages.Add(new LanguageInfo("fi", "fi", "Finnish")); options.Languages.Add(new LanguageInfo("fr", "fr", "Français")); options.Languages.Add(new LanguageInfo("hi", "hi", "Hindi", "in")); options.Languages.Add(new LanguageInfo("is", "is", "Icelandic", "is")); options.Languages.Add(new LanguageInfo("it", "it", "Italiano", "it")); options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português")); options.Languages.Add(new LanguageInfo("ro-RO", "ro-RO", "Română")); options.Languages.Add(new LanguageInfo("ru", "ru", "Русский")); options.Languages.Add(new LanguageInfo("sk", "sk", "Slovak")); options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe")); options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文")); options.Languages.Add(new LanguageInfo("de-DE", "de-DE", "Deutsch", "de")); options.Languages.Add(new LanguageInfo("es", "es", "Español")); }); } private void ConfigureSwaggerServices(IServiceCollection services) { services.AddAbpSwaggerGen( options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "BookStore API", Version = "v1" }); options.DocInclusionPredicate((docName, description) => true); options.CustomSchemaIds(type => type.FullName); } ); } private void ConfigureMenu(ServiceConfigurationContext context) { Configure(options => { options.MenuContributors.Add(new BookStoreMenuContributor()); }); } private void ConfigureRouter(ServiceConfigurationContext context) { Configure(options => { options.AppAssembly = typeof(BookStoreBlazorModule).Assembly; }); } private void ConfigureAutoApiControllers() { Configure(options => { options.ConventionalControllers.Create(typeof(BookStoreApplicationModule).Assembly); }); } private void ConfigureAutoMapper() { Configure(options => { options.AddMaps(); }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) { var env = context.GetEnvironment(); var app = context.GetApplicationBuilder(); app.UseAbpRequestLocalization(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseCorrelationId(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseJwtTokenMiddleware(); if (MultiTenancyConsts.IsEnabled) { app.UseMultiTenancy(); } app.UseUnitOfWork(); app.UseIdentityServer(); app.UseAuthorization(); app.UseSwagger(); app.UseAbpSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "BookStore API"); }); app.UseConfiguredEndpoints(); } }