Skip to content

Commit

Permalink
Disable CheckLibs if DataMigrationEnvironment or `IApplicationBui…
Browse files Browse the repository at this point in the history
…lder` is not available.
  • Loading branch information
maliming committed Aug 23, 2024
1 parent 32c68f1 commit c52d91f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,9 +15,12 @@ public class AbpAspNetCoreMvcUiBundlingModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpMvcLibsOptions>(options =>
if (!context.Services.IsDataMigrationEnvironment())
{
options.CheckLibs = true;
});
Configure<AbpMvcLibsOptions>(options =>
{
options.CheckLibs = true;
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
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;
Expand All @@ -25,7 +23,14 @@ public virtual void CheckLibs(ApplicationInitializationContext context)
var options = context.ServiceProvider.GetRequiredService<IOptions<AbpMvcLibsOptions>>().Value;
if (options.CheckLibs)
{
var app = context.GetApplicationBuilder();
var app = context.GetApplicationBuilderOrNull();
if (app == null)
{
var logger = context.ServiceProvider.GetRequiredService<ILogger<AbpMvcLibsService>>();
logger.LogWarning($"The {nameof(IApplicationBuilder)} is not available. The 'CheckLibs' feature is disabled!");
return;

Check warning on line 31 in framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs#L28-L31

Added lines #L28 - L31 were not covered by tests
}

app.Use(async (httpContext, next) =>
{
if (!await CheckLibsAsyncOnceAsync(httpContext))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ public static class ApplicationInitializationContextExtensions
{
public static IApplicationBuilder GetApplicationBuilder(this ApplicationInitializationContext context)
{
return context.ServiceProvider.GetRequiredService<IObjectAccessor<IApplicationBuilder>>().Value!;
var applicationBuilder = context.ServiceProvider.GetRequiredService<IObjectAccessor<IApplicationBuilder>>().Value;
Check.NotNull(applicationBuilder, nameof(applicationBuilder));
return applicationBuilder;
}

public static IApplicationBuilder? GetApplicationBuilderOrNull(this ApplicationInitializationContext context)
{
return context.ServiceProvider.GetRequiredService<IObjectAccessor<IApplicationBuilder>>().Value;
}

public static IWebHostEnvironment GetEnvironment(this ApplicationInitializationContext context)
Expand Down

0 comments on commit c52d91f

Please sign in to comment.