using Blazorise.Bootstrap5; using Blazorise.Icons.FontAwesome; using Microsoft.AspNetCore.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.OpenApi.Models; using MyCompanyName.MyProjectName.Data; using MyCompanyName.MyProjectName.Localization; using MyCompanyName.MyProjectName.Menus; using OpenIddict.Validation.AspNetCore; using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite; using Volo.Abp.AspNetCore.Components.Server.LeptonXLiteTheme; using Volo.Abp.AspNetCore.Components.Server.LeptonXLiteTheme.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite.Bundling; using Volo.Abp.AspNetCore.Components.Web.Theming.Routing; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.AuditLogging.MongoDB; using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; using Volo.Abp.MongoDB; using Volo.Abp.Emailing; using Volo.Abp.FeatureManagement; using Volo.Abp.FeatureManagement.Blazor.Server; using Volo.Abp.FeatureManagement.MongoDB; using Volo.Abp.Identity; using Volo.Abp.Identity.Blazor.Server; using Volo.Abp.Identity.MongoDB; using Volo.Abp.Localization; using Volo.Abp.Localization.ExceptionHandling; using Volo.Abp.Modularity; using Volo.Abp.OpenIddict.MongoDB; using Volo.Abp.PermissionManagement; using Volo.Abp.PermissionManagement.MongoDB; using Volo.Abp.PermissionManagement.HttpApi; using Volo.Abp.PermissionManagement.Identity; using Volo.Abp.PermissionManagement.OpenIddict; using Volo.Abp.SettingManagement; using Volo.Abp.SettingManagement.Blazor.Server; using Volo.Abp.SettingManagement.MongoDB; using Volo.Abp.Swashbuckle; using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.Blazor.Server; using Volo.Abp.TenantManagement.MongoDB; using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Uow; using Volo.Abp.Validation.Localization; using Volo.Abp.VirtualFileSystem; namespace MyCompanyName.MyProjectName; [DependsOn( // ABP Framework packages typeof(AbpAspNetCoreMvcModule), typeof(AbpAutofacModule), typeof(AbpAutoMapperModule), typeof(AbpSwashbuckleModule), typeof(AbpAspNetCoreSerilogModule), typeof(AbpAspNetCoreMvcUiLeptonXLiteThemeModule), typeof(AbpAspNetCoreComponentsServerLeptonXLiteThemeModule), // Account module packages typeof(AbpAccountApplicationModule), typeof(AbpAccountHttpApiModule), typeof(AbpAccountWebOpenIddictModule), // Identity module packages typeof(AbpPermissionManagementDomainIdentityModule), typeof(AbpPermissionManagementDomainOpenIddictModule), typeof(AbpIdentityApplicationModule), typeof(AbpIdentityHttpApiModule), typeof(AbpIdentityMongoDbModule), typeof(AbpOpenIddictMongoDbModule), typeof(AbpIdentityBlazorServerModule), // Audit logging module packages typeof(AbpAuditLoggingMongoDbModule), // Permission Management module packages typeof(AbpPermissionManagementApplicationModule), typeof(AbpPermissionManagementHttpApiModule), typeof(AbpPermissionManagementMongoDbModule), // Tenant Management module packages typeof(AbpTenantManagementApplicationModule), typeof(AbpTenantManagementHttpApiModule), typeof(AbpTenantManagementMongoDbModule), typeof(AbpTenantManagementBlazorServerModule), // Feature Management module packages typeof(AbpFeatureManagementApplicationModule), typeof(AbpFeatureManagementMongoDbModule), typeof(AbpFeatureManagementHttpApiModule), typeof(AbpFeatureManagementBlazorServerModule), // Setting Management module packages typeof(AbpSettingManagementApplicationModule), typeof(AbpSettingManagementMongoDbModule), typeof(AbpSettingManagementHttpApiModule), typeof(AbpSettingManagementBlazorServerModule) )] public class MyProjectNameModule : AbpModule { /* Single point to enable/disable multi-tenancy */ public const bool IsMultiTenant = true; public override void PreConfigureServices(ServiceConfigurationContext context) { context.Services.PreConfigure(options => { options.AddAssemblyResource( typeof(MyProjectNameResource), typeof(MyProjectNameModule).Assembly ); }); PreConfigure(builder => { builder.AddValidation(options => { options.AddAudiences("MyProjectName"); options.UseLocalServer(); options.UseAspNetCore(); }); }); } public override void ConfigureServices(ServiceConfigurationContext context) { var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = context.Services.GetConfiguration(); if (hostingEnvironment.IsDevelopment()) { context.Services.Replace(ServiceDescriptor.Singleton()); } ConfigureAuthentication(context); ConfigureUrls(configuration); ConfigureBundles(); ConfigureAutoMapper(context); ConfigureVirtualFiles(hostingEnvironment); ConfigureLocalizationServices(); ConfigureSwaggerServices(context.Services); ConfigureNavigationServices(); ConfigureAutoApiControllers(); ConfigureBlazorise(context); ConfigureRouter(context); ConfigureMongoDB(context); } private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); } 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( LeptonXLiteThemeBundles.Styles.Global, bundle => { bundle.AddFiles("/global-styles.css"); } ); //BLAZOR UI options.StyleBundles.Configure( BlazorLeptonXLiteThemeBundles.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("/MyCompanyName.MyProjectName.Blazor.Server.styles.css"); } ); }); } private void ConfigureLocalizationServices() { Configure(options => { options.Resources .Add("en") .AddBaseTypes(typeof(AbpValidationResource)) .AddVirtualJson("/Localization/MyProjectName"); options.DefaultResourceType = typeof(MyProjectNameResource); options.Languages.Add(new LanguageInfo("en", "en", "English")); options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe")); options.Languages.Add(new LanguageInfo("ar", "ar", "العربية")); options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština")); 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("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")); options.Languages.Add(new LanguageInfo("el", "el", "Ελληνικά")); }); Configure(options => { options.MapCodeNamespace("MyProjectName", typeof(MyProjectNameResource)); }); } private void ConfigureVirtualFiles(IWebHostEnvironment hostingEnvironment) { Configure(options => { options.FileSets.AddEmbedded(); if (hostingEnvironment.IsDevelopment()) { /* Using physical files in development, so we don't need to recompile on changes */ options.FileSets.ReplaceEmbeddedByPhysical(hostingEnvironment.ContentRootPath); } }); } private void ConfigureSwaggerServices(IServiceCollection services) { services.AddAbpSwaggerGen( options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProjectName API", Version = "v1" }); options.DocInclusionPredicate((docName, description) => true); options.CustomSchemaIds(type => type.FullName); } ); } private void ConfigureBlazorise(ServiceConfigurationContext context) { context.Services .AddBootstrap5Providers() .AddFontAwesomeIcons(); } private void ConfigureRouter(ServiceConfigurationContext context) { Configure(options => { options.AppAssembly = typeof(MyProjectNameModule).Assembly; }); } private void ConfigureNavigationServices() { Configure(options => { options.MenuContributors.Add(new MyProjectNameMenuContributor()); }); } private void ConfigureAutoApiControllers() { Configure(options => { options.ConventionalControllers.Create(typeof(MyProjectNameModule).Assembly); }); } private void ConfigureAutoMapper(ServiceConfigurationContext context) { context.Services.AddAutoMapperObjectMapper(); Configure(options => { options.AddMaps(); }); } private void ConfigureMongoDB(ServiceConfigurationContext context) { context.Services.AddMongoDbContext(options => { options.AddDefaultRepositories(); }); Configure(options => { options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; }); } 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.UseAbpOpenIddictValidation(); if (IsMultiTenant) { app.UseMultiTenancy(); } app.UseUnitOfWork(); app.UseAuthorization(); app.UseSwagger(); app.UseAbpSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API"); }); app.UseAuditing(); app.UseAbpSerilogEnrichers(); app.UseConfiguredEndpoints(); } }