diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpAspNetCoreMvcUiBundlingModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpAspNetCoreMvcUiBundlingModule.cs index 4e020bfcf82..f0f7f944396 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpAspNetCoreMvcUiBundlingModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpAspNetCoreMvcUiBundlingModule.cs @@ -1,5 +1,6 @@ using Volo.Abp.AspNetCore.Mvc.Libs; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; +using Volo.Abp.Data; using Volo.Abp.Minify; using Volo.Abp.Modularity; @@ -14,9 +15,12 @@ public class AbpAspNetCoreMvcUiBundlingModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { - Configure(options => + if (!context.Services.IsDataMigrationEnvironment()) { - options.CheckLibs = true; - }); + Configure(options => + { + options.CheckLibs = true; + }); + } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs index 1329fa5e27f..1d122549342 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Linq; using System.Net; using System.Text; @@ -7,7 +6,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -25,7 +23,14 @@ public virtual void CheckLibs(ApplicationInitializationContext context) var options = context.ServiceProvider.GetRequiredService>().Value; if (options.CheckLibs) { - var app = context.GetApplicationBuilder(); + var app = context.GetApplicationBuilderOrNull(); + if (app == null) + { + var logger = context.ServiceProvider.GetRequiredService>(); + logger.LogWarning($"The {nameof(IApplicationBuilder)} is not available. The 'CheckLibs' feature is disabled!"); + return; + } + app.Use(async (httpContext, next) => { if (!await CheckLibsAsyncOnceAsync(httpContext)) diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs index 045b2934895..1f6e3c17bf5 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs @@ -12,7 +12,14 @@ public static class ApplicationInitializationContextExtensions { public static IApplicationBuilder GetApplicationBuilder(this ApplicationInitializationContext context) { - return context.ServiceProvider.GetRequiredService>().Value!; + var applicationBuilder = context.ServiceProvider.GetRequiredService>().Value; + Check.NotNull(applicationBuilder, nameof(applicationBuilder)); + return applicationBuilder; + } + + public static IApplicationBuilder? GetApplicationBuilderOrNull(this ApplicationInitializationContext context) + { + return context.ServiceProvider.GetRequiredService>().Value; } public static IWebHostEnvironment GetEnvironment(this ApplicationInitializationContext context)