diff --git a/framework/src/Volo.Abp.AspNetCore.Bundling/Volo/Abp/AspNetCore/Bundling/AbpGlobalAssetsBundleServiceBase.cs b/framework/src/Volo.Abp.AspNetCore.Bundling/Volo/Abp/AspNetCore/Bundling/AbpGlobalAssetsBundleServiceBase.cs new file mode 100644 index 0000000000..eca09af1bb --- /dev/null +++ b/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 : IAbpGlobalAssetsBundleService, ITransientDependency + where TGlobalAssetsBundleService : class, IAbpGlobalAssetsBundleService +{ + public ILogger Logger { get; set; } + + protected IOptions AbpBundlingOptions { get; } + protected IBundleManager BundleManager { get; } + + protected AbpGlobalAssetsBundleServiceBase( + IOptions abpBundlingOptions, + IBundleManager bundleManager) + { + AbpBundlingOptions = abpBundlingOptions; + BundleManager = bundleManager; + + Logger = NullLogger.Instance; + } + + public async Task 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().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 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().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); +} diff --git a/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpAspNetCoreComponentsMauiBlazorBundlingModule.cs b/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpAspNetCoreComponentsMauiBlazorBundlingModule.cs index 07900b0fb0..c9f62dcc99 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpAspNetCoreComponentsMauiBlazorBundlingModule.cs +++ b/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>().Value; - var logger = context.ServiceProvider.GetRequiredService>(); - if (!bundlingOptions.GlobalAssets.Enabled) - { - return; - } - - var bundleManager = context.ServiceProvider.GetRequiredService(); - var mauiBlazorContentFileProvider = context.ServiceProvider.GetRequiredService(); - var dynamicFileProvider = context.ServiceProvider.GetRequiredService(); - 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)); - } - } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpBlazorWebView.cs b/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpBlazorWebView.cs index bbb5829162..0a2392f150 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpBlazorWebView.cs +++ b/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(), base.CreateFileProvider(contentRootDir)); + return new CompositeFileProvider(base.CreateFileProvider(contentRootDir), Handler!.GetRequiredService()); } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpGlobalAssetsBundleService.cs b/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/AbpGlobalAssetsBundleService.cs new file mode 100644 index 0000000000..bbdb99fd3c --- /dev/null +++ b/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 +{ + protected IFileProvider MauiBlazorContentFileProvider { get; } + protected string RootPath = "/wwwroot"; + + public AbpGlobalAssetsBundleService( + IOptions 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); + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/MauiBlazorContentFileProvider.cs b/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/MauiBlazorContentFileProvider.cs index cc7bbf570e..612f3e8f00 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Bundling/Volo/Abp/AspNetCore/Components/MauiBlazor/Bundling/MauiBlazorContentFileProvider.cs +++ b/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 { get; } - public MauiBlazorContentFileProvider(IVirtualFileProvider virtualFileProvider) + public MauiBlazorContentFileProvider( + IAbpGlobalAssetsBundleService abpGlobalAssetsBundleService, + IOptions 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; } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IAbpGlobalAssetsBundleService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IAbpGlobalAssetsBundleService.cs new file mode 100644 index 0000000000..f891bc2f07 --- /dev/null +++ b/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 GetStylesAsync(); + + Task GetScriptsAsync(); +} 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 13b157748b..69d834e570 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,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, AbpBundlingGlobalAssetsOptionsValidation>(); + Configure(options => { - environment.WebRootFileProvider = - new CompositeFileProvider( - context.GetEnvironment().WebRootFileProvider, - context.ServiceProvider.GetRequiredService() - ); - } - - await InitialGlobalAssetsAsync(context); - } - - protected virtual async Task InitialGlobalAssetsAsync(ApplicationInitializationContext context) - { - var bundlingOptions = context.ServiceProvider.GetRequiredService>().Value; - var logger = context.ServiceProvider.GetRequiredService>(); - if (!bundlingOptions.GlobalAssets.Enabled) - { - return; - } - - var bundleManager = context.ServiceProvider.GetRequiredService(); - var webHostEnvironment = context.ServiceProvider.GetRequiredService(); - var dynamicFileProvider = context.ServiceProvider.GetRequiredService(); - 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>().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(); + 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(); + 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() + ); } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpBundlingGlobalAssetsOptionsValidation.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpBundlingGlobalAssetsOptionsValidation.cs new file mode 100644 index 0000000000..a50170a2dc --- /dev/null +++ b/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 +{ + 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; + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpGlobalAssetsBundleService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpGlobalAssetsBundleService.cs new file mode 100644 index 0000000000..1c837f40ae --- /dev/null +++ b/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 +{ + protected IWebHostEnvironment WebHostEnvironment { get; } + + public AbpGlobalAssetsBundleService( + IOptions abpBundlingOptions, + IBundleManager bundleManager, + IWebHostEnvironment webHostEnvironment) + : base(abpBundlingOptions, bundleManager) + { + WebHostEnvironment = webHostEnvironment; + } + + protected override IFileInfo? GetFileInfo(string fileName) + { + return WebHostEnvironment.WebRootFileProvider?.GetFileInfo(fileName); + } +}