Browse Source

Add `IAbpGlobalAssetsBundleService` to get styles&scripts.

update-bundle
maliming 9 months ago
parent
commit
588a5f4791
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 93
      framework/src/Volo.Abp.AspNetCore.Bundling/Volo/Abp/AspNetCore/Bundling/AbpGlobalAssetsBundleServiceBase.cs
  2. 96
      framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpAspNetCoreComponentsMauiBlazorBundlingModule.cs
  3. 4
      framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpBlazorWebView.cs
  4. 39
      framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpGlobalAssetsBundleService.cs
  5. 58
      framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/MauiBlazorContentFileProvider.cs
  6. 10
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IAbpGlobalAssetsBundleService.cs
  7. 125
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpAspNetCoreMvcUiBundlingModule.cs
  8. 25
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpBundlingGlobalAssetsOptionsValidation.cs
  9. 25
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpGlobalAssetsBundleService.cs

93
framework/src/Volo.Abp.AspNetCore.Bundling/Volo/Abp/AspNetCore/Bundling/AbpGlobalAssetsBundleServiceBase.cs

@ -0,0 +1,93 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.Bundling.Styles;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Bundling;
public abstract class AbpGlobalAssetsBundleServiceBase<TGlobalAssetsBundleService> : IAbpGlobalAssetsBundleService, ITransientDependency
where TGlobalAssetsBundleService : class, IAbpGlobalAssetsBundleService
{
public ILogger<TGlobalAssetsBundleService> Logger { get; set; }
protected IOptions<AbpBundlingOptions> AbpBundlingOptions { get; }
protected IBundleManager BundleManager { get; }
protected AbpGlobalAssetsBundleServiceBase(
IOptions<AbpBundlingOptions> abpBundlingOptions,
IBundleManager bundleManager)
{
AbpBundlingOptions = abpBundlingOptions;
BundleManager = bundleManager;
Logger = NullLogger<TGlobalAssetsBundleService>.Instance;
}
public async Task<string> GetStylesAsync()
{
var styleFiles = await BundleManager.GetStyleBundleFilesAsync(AbpBundlingOptions.Value.GlobalAssets.GlobalStyleBundleName!);
var styles = string.Empty;
foreach (var file in styleFiles)
{
var fileInfo = GetFileInfo(file.FileName);
if (fileInfo == null || !fileInfo.Exists)
{
Logger.LogError($"Could not find the file: {file.FileName}");
continue;
}
var fileContent = await fileInfo.ReadAsStringAsync();
if (!BundleManager.As<BundleManagerBase>().IsBundlingEnabled())
{
fileContent = CssRelativePath.Adjust(fileContent,
file.FileName,
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"));
styles += $"/*{file.FileName}*/{Environment.NewLine}{fileContent}{Environment.NewLine}{Environment.NewLine}";
}
else
{
styles += $"{fileContent}{Environment.NewLine}{Environment.NewLine}";
}
}
return styles;
}
public virtual async Task<string> GetScriptsAsync()
{
var scriptFiles = await BundleManager.GetScriptBundleFilesAsync(AbpBundlingOptions.Value.GlobalAssets.GlobalScriptBundleName!);
var scripts = string.Empty;
foreach (var file in scriptFiles)
{
var fileInfo = GetFileInfo(file.FileName);
if (fileInfo == null || !fileInfo.Exists)
{
Logger.LogError($"Could not find the file: {file.FileName}");
continue;
}
var fileContent = await fileInfo.ReadAsStringAsync();
if (!BundleManager.As<BundleManagerBase>().IsBundlingEnabled())
{
scripts += $"{fileContent.EnsureEndsWith(';')}{Environment.NewLine}{Environment.NewLine}";
}
else
{
scripts += $"//{file.FileName}{Environment.NewLine}{fileContent.EnsureEndsWith(';')}{Environment.NewLine}{Environment.NewLine}";
}
}
return scripts;
}
protected abstract IFileInfo? GetFileInfo(string fileName);
}

96
framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpAspNetCoreComponentsMauiBlazorBundlingModule.cs

@ -1,17 +1,7 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.Bundling.Styles;
using Volo.Abp.EventBus;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling;
@ -25,86 +15,4 @@ public class AbpAspNetCoreComponentsMauiBlazorBundlingModule : AbpModule
{
AsyncHelper.RunSync(() => OnApplicationInitializationAsync(context));
}
public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
await InitialGlobalAssetsAsync(context);
}
protected virtual async Task InitialGlobalAssetsAsync(ApplicationInitializationContext context)
{
var bundlingOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpBundlingOptions>>().Value;
var logger = context.ServiceProvider.GetRequiredService<ILogger<AbpAspNetCoreComponentsMauiBlazorBundlingModule>>();
if (!bundlingOptions.GlobalAssets.Enabled)
{
return;
}
var bundleManager = context.ServiceProvider.GetRequiredService<BundleManager>();
var mauiBlazorContentFileProvider = context.ServiceProvider.GetRequiredService<IMauiBlazorContentFileProvider>();
var dynamicFileProvider = context.ServiceProvider.GetRequiredService<IDynamicFileProvider>();
if (!bundlingOptions.GlobalAssets.GlobalStyleBundleName.IsNullOrWhiteSpace())
{
var styleFiles = await bundleManager.GetStyleBundleFilesAsync(bundlingOptions.GlobalAssets.GlobalStyleBundleName);
var styles = string.Empty;
foreach (var file in styleFiles)
{
var fileInfo = mauiBlazorContentFileProvider.GetFileInfo(file.FileName);
if (!fileInfo.Exists)
{
logger.LogError($"Could not find the file: {file.FileName}");
continue;
}
var fileContent = await fileInfo.ReadAsStringAsync();
if (!bundleManager.IsBundlingEnabled())
{
fileContent = CssRelativePath.Adjust(fileContent,
file.FileName,
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"));
styles += $"/*{file.FileName}*/{Environment.NewLine}{fileContent}{Environment.NewLine}{Environment.NewLine}";
}
else
{
styles += $"{fileContent}{Environment.NewLine}{Environment.NewLine}";
}
}
dynamicFileProvider.AddOrUpdate(
new InMemoryFileInfo("/wwwroot/" + bundlingOptions.GlobalAssets.CssFileName,
Encoding.UTF8.GetBytes(styles),
bundlingOptions.GlobalAssets.CssFileName));
}
if (!bundlingOptions.GlobalAssets.GlobalScriptBundleName.IsNullOrWhiteSpace())
{
var scriptFiles = await bundleManager.GetScriptBundleFilesAsync(bundlingOptions.GlobalAssets.GlobalScriptBundleName);
var scripts = string.Empty;
foreach (var file in scriptFiles)
{
var fileInfo = mauiBlazorContentFileProvider.GetFileInfo(file.FileName);
if (!fileInfo.Exists)
{
logger.LogError($"Could not find the file: {file.FileName}");
continue;
}
var fileContent = await fileInfo.ReadAsStringAsync();
if (!bundleManager.IsBundlingEnabled())
{
scripts += $"{fileContent.EnsureEndsWith(';')}{Environment.NewLine}{Environment.NewLine}";
}
else
{
scripts += $"//{file.FileName}{Environment.NewLine}{fileContent.EnsureEndsWith(';')}{Environment.NewLine}{Environment.NewLine}";
}
}
dynamicFileProvider.AddOrUpdate(
new InMemoryFileInfo("/wwwroot/" + bundlingOptions.GlobalAssets.JavaScriptFileName,
Encoding.UTF8.GetBytes(scripts),
bundlingOptions.GlobalAssets.JavaScriptFileName));
}
}
}
}

4
framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpBlazorWebView.cs

@ -8,6 +8,6 @@ public class AbpBlazorWebView : BlazorWebView
{
public override IFileProvider CreateFileProvider(string contentRootDir)
{
return new CompositeFileProvider(Handler!.GetRequiredService<IMauiBlazorContentFileProvider>(), base.CreateFileProvider(contentRootDir));
return new CompositeFileProvider(base.CreateFileProvider(contentRootDir), Handler!.GetRequiredService<IMauiBlazorContentFileProvider>());
}
}
}

39
framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpGlobalAssetsBundleService.cs

@ -0,0 +1,39 @@
using System.IO;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Options;
using Microsoft.Maui.Storage;
using Volo.Abp.AspNetCore.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
namespace Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling;
public class AbpGlobalAssetsBundleService : AbpGlobalAssetsBundleServiceBase<AbpGlobalAssetsBundleService>
{
protected IFileProvider MauiBlazorContentFileProvider { get; }
protected string RootPath = "/wwwroot";
public AbpGlobalAssetsBundleService(
IOptions<AbpBundlingOptions> abpBundlingOptions,
IBundleManager bundleManager)
: base(abpBundlingOptions, bundleManager)
{
MauiBlazorContentFileProvider = CreateMauiBlazorContentFileProvider();
}
protected virtual IFileProvider CreateMauiBlazorContentFileProvider()
{
var assetsDirectory = Path.Combine(FileSystem.Current.AppDataDirectory, "wwwroot");
if (!Path.Exists(assetsDirectory))
{
Directory.CreateDirectory(assetsDirectory);
}
return new PhysicalFileProvider(assetsDirectory);
}
protected override IFileInfo? GetFileInfo(string fileName)
{
return MauiBlazorContentFileProvider.GetFileInfo(fileName);
}
}

58
framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/MauiBlazorContentFileProvider.cs

@ -1,24 +1,27 @@
using System;
using System.IO;
using System.Text;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Storage;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Threading;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling;
public class MauiBlazorContentFileProvider : IMauiBlazorContentFileProvider, ISingletonDependency
{
private readonly IVirtualFileProvider _virtualFileProvider;
private readonly IFileProvider _fileProvider;
private string _rootPath = "/wwwroot";
protected IAbpGlobalAssetsBundleService AbpGlobalAssetsBundleService { get; }
protected IOptions<AbpBundlingOptions> AbpBundlingOptions { get; }
public MauiBlazorContentFileProvider(IVirtualFileProvider virtualFileProvider)
public MauiBlazorContentFileProvider(
IAbpGlobalAssetsBundleService abpGlobalAssetsBundleService,
IOptions<AbpBundlingOptions> abpBundlingOptions)
{
_virtualFileProvider = virtualFileProvider;
_fileProvider = CreateFileProvider();
AbpGlobalAssetsBundleService = abpGlobalAssetsBundleService;
AbpBundlingOptions = abpBundlingOptions;
}
public string ContentRootPath => FileSystem.Current.AppDataDirectory;
@ -30,39 +33,28 @@ public class MauiBlazorContentFileProvider : IMauiBlazorContentFileProvider, ISi
return new NotFoundFileInfo(subpath);
}
var fileInfo = _fileProvider.GetFileInfo(subpath);
return fileInfo.Exists ? fileInfo : _fileProvider.GetFileInfo( _rootPath + subpath.EnsureStartsWith('/'));
}
if (string.Equals(subpath, AbpBundlingOptions.Value.GlobalAssets.GlobalStyleBundleName!, StringComparison.OrdinalIgnoreCase))
{
var styles = AsyncHelper.RunSync(() => AbpGlobalAssetsBundleService.GetStylesAsync());
return new InMemoryFileInfo(subpath, Encoding.UTF8.GetBytes(styles), AbpBundlingOptions.Value.GlobalAssets.GlobalStyleBundleName!);
}
public IDirectoryContents GetDirectoryContents(string subpath)
{
if (string.IsNullOrEmpty(subpath))
if (string.Equals(subpath, AbpBundlingOptions.Value.GlobalAssets.GlobalScriptBundleName!, StringComparison.OrdinalIgnoreCase))
{
return NotFoundDirectoryContents.Singleton;
var scripts = AsyncHelper.RunSync(() => AbpGlobalAssetsBundleService.GetScriptsAsync());
return new InMemoryFileInfo(subpath, Encoding.UTF8.GetBytes(scripts), AbpBundlingOptions.Value.GlobalAssets.GlobalScriptBundleName!);
}
var directory = _fileProvider.GetDirectoryContents(subpath);
return directory.Exists ? directory : _fileProvider.GetDirectoryContents( _rootPath + subpath.EnsureStartsWith('/'));
return new NotFoundFileInfo(subpath);
}
public IChangeToken Watch(string filter)
public IDirectoryContents GetDirectoryContents(string subpath)
{
return new CompositeChangeToken(
[
_fileProvider.Watch(_rootPath + filter),
_fileProvider.Watch(filter)
]
);
return NotFoundDirectoryContents.Singleton;
}
protected virtual IFileProvider CreateFileProvider()
public IChangeToken Watch(string filter)
{
var assetsDirectory = Path.Combine(ContentRootPath, _rootPath.TrimStart('/'));
if (!Path.Exists(assetsDirectory))
{
Directory.CreateDirectory(assetsDirectory);
}
return new CompositeFileProvider(new PhysicalFileProvider(assetsDirectory), _virtualFileProvider);
return NullChangeToken.Singleton;
}
}
}

10
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IAbpGlobalAssetsBundleService.cs

@ -0,0 +1,10 @@
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling;
public interface IAbpGlobalAssetsBundleService
{
Task<string> GetStylesAsync();
Task<string> GetScriptsAsync();
}

125
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpAspNetCoreMvcUiBundlingModule.cs

@ -1,29 +1,22 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.Bundling.Styles;
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;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling;
[DependsOn(
typeof(AbpAspNetCoreMvcUiBootstrapModule),
typeof(AbpAspNetCoreBundlingModule)
)]
)]
public class AbpAspNetCoreMvcUiBundlingModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
@ -35,97 +28,47 @@ public class AbpAspNetCoreMvcUiBundlingModule : AbpModule
options.CheckLibs = true;
});
}
}
public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
var environment = context.GetEnvironmentOrNull();
if (environment != null)
context.Services.AddSingleton<IValidateOptions<AbpBundlingOptions>, AbpBundlingGlobalAssetsOptionsValidation>();
Configure<AbpEndpointRouterOptions>(options =>
{
environment.WebRootFileProvider =
new CompositeFileProvider(
context.GetEnvironment().WebRootFileProvider,
context.ServiceProvider.GetRequiredService<IWebContentFileProvider>()
);
}
await InitialGlobalAssetsAsync(context);
}
protected virtual async Task InitialGlobalAssetsAsync(ApplicationInitializationContext context)
{
var bundlingOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpBundlingOptions>>().Value;
var logger = context.ServiceProvider.GetRequiredService<ILogger<AbpAspNetCoreMvcUiBundlingModule>>();
if (!bundlingOptions.GlobalAssets.Enabled)
{
return;
}
var bundleManager = context.ServiceProvider.GetRequiredService<BundleManager>();
var webHostEnvironment = context.ServiceProvider.GetRequiredService<IWebHostEnvironment>();
var dynamicFileProvider = context.ServiceProvider.GetRequiredService<IDynamicFileProvider>();
if (!bundlingOptions.GlobalAssets.GlobalStyleBundleName.IsNullOrWhiteSpace())
{
var styleFiles = await bundleManager.GetStyleBundleFilesAsync(bundlingOptions.GlobalAssets.GlobalStyleBundleName);
var styles = string.Empty;
foreach (var file in styleFiles)
options.EndpointConfigureActions.Add(endpointContext =>
{
var fileInfo = webHostEnvironment.WebRootFileProvider?.GetFileInfo(file.FileName);
if (fileInfo == null || !fileInfo.Exists)
var abpBundlingOptions = endpointContext.ScopeServiceProvider.GetRequiredService<IOptions<AbpBundlingOptions>>().Value;
if (!abpBundlingOptions.GlobalAssets.Enabled)
{
logger.LogError($"Could not find the file: {file.FileName}");
continue;
return;
}
var fileContent = await fileInfo.ReadAsStringAsync();
if (!bundleManager.IsBundlingEnabled())
endpointContext.Endpoints.MapGet(abpBundlingOptions.GlobalAssets.CssFileName, async httpContext =>
{
fileContent = CssRelativePath.Adjust(fileContent,
file.FileName,
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"));
var abpGlobalAssetsBundleService = httpContext.RequestServices.GetRequiredService<IAbpGlobalAssetsBundleService>();
var styles = await abpGlobalAssetsBundleService.GetStylesAsync();
httpContext.Response.ContentType = "text/css";
await httpContext.Response.WriteAsync(styles);
});
styles += $"/*{file.FileName}*/{Environment.NewLine}{fileContent}{Environment.NewLine}{Environment.NewLine}";
}
else
endpointContext.Endpoints.MapGet(abpBundlingOptions.GlobalAssets.JavaScriptFileName, async httpContext =>
{
styles += $"{fileContent}{Environment.NewLine}{Environment.NewLine}";
}
}
dynamicFileProvider.AddOrUpdate(
new InMemoryFileInfo("/wwwroot/" + bundlingOptions.GlobalAssets.CssFileName,
Encoding.UTF8.GetBytes(styles),
bundlingOptions.GlobalAssets.CssFileName));
}
var abpGlobalAssetsBundleService = httpContext.RequestServices.GetRequiredService<IAbpGlobalAssetsBundleService>();
var scripts = await abpGlobalAssetsBundleService.GetScriptsAsync();
httpContext.Response.ContentType = "text/javascript";
await httpContext.Response.WriteAsync(scripts);
});
});
});
}
if (!bundlingOptions.GlobalAssets.GlobalScriptBundleName.IsNullOrWhiteSpace())
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var environment = context.GetEnvironmentOrNull();
if (environment != null)
{
var scriptFiles = await bundleManager.GetScriptBundleFilesAsync(bundlingOptions.GlobalAssets.GlobalScriptBundleName);
var scripts = string.Empty;
foreach (var file in scriptFiles)
{
var fileInfo = webHostEnvironment.WebRootFileProvider?.GetFileInfo(file.FileName);
if (fileInfo == null || !fileInfo.Exists)
{
logger.LogError($"Could not find the file: {file.FileName}");
continue;
}
var fileContent = await fileInfo.ReadAsStringAsync();
if (!bundleManager.IsBundlingEnabled())
{
scripts += $"{fileContent.EnsureEndsWith(';')}{Environment.NewLine}{Environment.NewLine}";
}
else
{
scripts += $"//{file.FileName}{Environment.NewLine}{fileContent.EnsureEndsWith(';')}{Environment.NewLine}{Environment.NewLine}";
}
}
dynamicFileProvider.AddOrUpdate(
new InMemoryFileInfo("/wwwroot/" + bundlingOptions.GlobalAssets.JavaScriptFileName,
Encoding.UTF8.GetBytes(scripts),
bundlingOptions.GlobalAssets.JavaScriptFileName));
environment.WebRootFileProvider =
new CompositeFileProvider(
context.GetEnvironment().WebRootFileProvider,
context.ServiceProvider.GetRequiredService<IWebContentFileProvider>()
);
}
}
}

25
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpBundlingGlobalAssetsOptionsValidation.cs

@ -0,0 +1,25 @@
using System;
using Microsoft.Extensions.Options;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling;
public class AbpBundlingGlobalAssetsOptionsValidation : IValidateOptions<AbpBundlingOptions>
{
public ValidateOptionsResult Validate(string? name, AbpBundlingOptions options)
{
if (options.GlobalAssets.Enabled)
{
if (options.GlobalAssets.JavaScriptFileName.IsNullOrWhiteSpace())
{
return ValidateOptionsResult.Fail("JavaScriptFileName property must be set when GlobalAssets is enabled.");
}
if (options.GlobalAssets.CssFileName.IsNullOrWhiteSpace())
{
return ValidateOptionsResult.Fail("CssFileName property must be set when GlobalAssets is enabled.");
}
}
return ValidateOptionsResult.Success;
}
}

25
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpGlobalAssetsBundleService.cs

@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Bundling;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling;
public class AbpGlobalAssetsBundleService : AbpGlobalAssetsBundleServiceBase<AbpGlobalAssetsBundleService>
{
protected IWebHostEnvironment WebHostEnvironment { get; }
public AbpGlobalAssetsBundleService(
IOptions<AbpBundlingOptions> abpBundlingOptions,
IBundleManager bundleManager,
IWebHostEnvironment webHostEnvironment)
: base(abpBundlingOptions, bundleManager)
{
WebHostEnvironment = webHostEnvironment;
}
protected override IFileInfo? GetFileInfo(string fileName)
{
return WebHostEnvironment.WebRootFileProvider?.GetFileInfo(fileName);
}
}
Loading…
Cancel
Save