diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs index b53f54af7c..227653bdc9 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs @@ -10,7 +10,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling return bundleConfiguration; } - public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params BundleContributor[] contributors) + public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params IBundleContributor[] contributors) { Check.NotNull(contributors, nameof(contributors)); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributor.cs index c1d8963d88..1fa25140bd 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributor.cs @@ -1,23 +1,49 @@ -namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling +using System; +using System.Threading.Tasks; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling { - public abstract class BundleContributor + public abstract class BundleContributor : IBundleContributor { + public virtual Task PreConfigureBundleAsync(BundleConfigurationContext context) + { + PreConfigureBundle(context); + return Task.CompletedTask; + } + public virtual void PreConfigureBundle(BundleConfigurationContext context) { } + public virtual Task ConfigureBundleAsync(BundleConfigurationContext context) + { + ConfigureBundle(context); + return Task.CompletedTask; + } + public virtual void ConfigureBundle(BundleConfigurationContext context) { } + public virtual Task PostConfigureBundleAsync(BundleConfigurationContext context) + { + PostConfigureBundle(context); + return Task.CompletedTask; + } + public virtual void PostConfigureBundle(BundleConfigurationContext context) { } - //TODO: Reconsider naming and usage! + public virtual Task ConfigureDynamicResourcesAsync(BundleConfigurationContext context) + { + ConfigureDynamicResources(context); + return Task.CompletedTask; + } + public virtual void ConfigureDynamicResources(BundleConfigurationContext context) { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs index 1bd62ff816..8389f7b9ed 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs @@ -9,14 +9,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling { public class BundleContributorCollection { - private readonly List _contributors; + private readonly List _contributors; public BundleContributorCollection() { - _contributors = new List(); + _contributors = new List(); } - public void Add(BundleContributor contributor) + public void Add(IBundleContributor contributor) { foreach (var dependedType in GetDirectDependencies(contributor.GetType())) { @@ -27,7 +27,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling } public void Add() - where TContributor : BundleContributor, new() + where TContributor : IBundleContributor, new() { Add(typeof(TContributor)); } @@ -39,7 +39,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling AddWithDependencies(contributorType); } - public IReadOnlyList GetAll() + public IReadOnlyList GetAll() { return _contributors.ToImmutableList(); } @@ -77,14 +77,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling private void AddInstanceToContributors(Type contributorType) { - if (!typeof(BundleContributor).IsAssignableFrom(contributorType)) + if (!typeof(IBundleContributor).IsAssignableFrom(contributorType)) { - throw new AbpException($"Given {nameof(contributorType)} ({contributorType.AssemblyQualifiedName}) should implement the {typeof(BundleContributor).AssemblyQualifiedName} interface!"); + throw new AbpException($"Given {nameof(contributorType)} ({contributorType.AssemblyQualifiedName}) should implement the {typeof(IBundleContributor).AssemblyQualifiedName} interface!"); } try { - _contributors.Add((BundleContributor)Activator.CreateInstance(contributorType)); + _contributors.Add((IBundleContributor)Activator.CreateInstance(contributorType)); } catch (Exception ex) { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs index 48290291bf..f5806364f3 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -58,21 +59,21 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling Logger = NullLogger.Instance; } - public virtual IReadOnlyList GetStyleBundleFiles(string bundleName) + public virtual async Task> GetStyleBundleFilesAsync(string bundleName) { - return GetBundleFiles(Options.StyleBundles, bundleName, StyleBundler); + return await GetBundleFilesAsync(Options.StyleBundles, bundleName, StyleBundler); } - public virtual IReadOnlyList GetScriptBundleFiles(string bundleName) + public virtual async Task> GetScriptBundleFilesAsync(string bundleName) { - return GetBundleFiles(Options.ScriptBundles, bundleName, ScriptBundler); + return await GetBundleFilesAsync(Options.ScriptBundles, bundleName, ScriptBundler); } - protected virtual IReadOnlyList GetBundleFiles(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) + protected virtual async Task> GetBundleFilesAsync(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) { var contributors = GetContributors(bundles, bundleName); - var bundleFiles = RequestResources.TryAdd(GetBundleFiles(contributors)); - var dynamicResources = RequestResources.TryAdd(GetDynamicResources(contributors)); + var bundleFiles = RequestResources.TryAdd(await GetBundleFilesAsync(contributors)); + var dynamicResources = RequestResources.TryAdd(await GetDynamicResourcesAsync(contributors)); if (!IsBundlingEnabled()) { @@ -178,22 +179,36 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling } } - protected virtual List GetBundleFiles(List contributors) + protected async Task> GetBundleFilesAsync(List contributors) { var context = CreateBundleConfigurationContext(); - contributors.ForEach(c => c.PreConfigureBundle(context)); - contributors.ForEach(c => c.ConfigureBundle(context)); - contributors.ForEach(c => c.PostConfigureBundle(context)); + foreach (var contributor in contributors) + { + await contributor.PreConfigureBundleAsync(context); + } + + foreach (var contributor in contributors) + { + await contributor.ConfigureBundleAsync(context); + } + + foreach (var contributor in contributors) + { + await contributor.PostConfigureBundleAsync(context); + } return context.Files; } - protected virtual List GetDynamicResources(List contributors) + protected virtual async Task> GetDynamicResourcesAsync(List contributors) { var context = CreateBundleConfigurationContext(); - contributors.ForEach(c => c.ConfigureDynamicResources(context)); + foreach (var contributor in contributors) + { + await contributor.ConfigureDynamicResourcesAsync(context); + } return context.Files; } @@ -203,9 +218,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling return new BundleConfigurationContext(ServiceProvider, WebContentFileProvider); } - protected virtual List GetContributors(BundleConfigurationCollection bundles, string bundleName) + protected virtual List GetContributors(BundleConfigurationCollection bundles, string bundleName) { - var contributors = new List(); + var contributors = new List(); AddContributorsWithBaseBundles(contributors, bundles, bundleName); @@ -222,7 +237,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling return contributors; } - protected virtual void AddContributorsWithBaseBundles(List contributors, BundleConfigurationCollection bundles, string bundleName) + protected virtual void AddContributorsWithBaseBundles(List contributors, BundleConfigurationCollection bundles, string bundleName) { var bundleConfiguration = bundles.Get(bundleName); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleContributor.cs new file mode 100644 index 0000000000..996eeb4a30 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleContributor.cs @@ -0,0 +1,15 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling +{ + public interface IBundleContributor + { + Task PreConfigureBundleAsync(BundleConfigurationContext context); + + Task ConfigureBundleAsync(BundleConfigurationContext context); + + Task PostConfigureBundleAsync(BundleConfigurationContext context); + + Task ConfigureDynamicResourcesAsync(BundleConfigurationContext context); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs index 39b092a00a..4188c0e7aa 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs @@ -1,11 +1,12 @@ using System.Collections.Generic; +using System.Threading.Tasks; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling { public interface IBundleManager { - IReadOnlyList GetStyleBundleFiles(string bundleName); + Task> GetStyleBundleFilesAsync(string bundleName); - IReadOnlyList GetScriptBundleFiles(string bundleName); + Task> GetScriptBundleFilesAsync(string bundleName); } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs index 8eb6903592..73b6e025ea 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs @@ -16,7 +16,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers public abstract class AbpTagHelperResourceService : ITransientDependency { public ILogger Logger { get; set; } - protected IBundleManager BundleManager { get; } protected IWebContentFileProvider WebContentFileProvider { get; } protected IWebHostEnvironment HostingEnvironment { get; } @@ -36,7 +35,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers Logger = NullLogger.Instance; } - public virtual Task ProcessAsync( + public virtual async Task ProcessAsync( [NotNull] TagHelperContext context, [NotNull] TagHelperOutput output, [NotNull] List bundleItems, @@ -57,7 +56,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers CreateBundle(bundleName, bundleItems); - var bundleFiles = GetBundleFiles(bundleName); + var bundleFiles = await GetBundleFilesAsync(bundleName); output.Content.Clear(); @@ -74,13 +73,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers stopwatch.Stop(); Logger.LogDebug($"Added bundle '{bundleName}' to the page in {stopwatch.Elapsed.TotalMilliseconds:0.00} ms."); - - return Task.CompletedTask; } protected abstract void CreateBundle(string bundleName, List bundleItems); - protected abstract IReadOnlyList GetBundleFiles(string bundleName); + protected abstract Task> GetBundleFilesAsync(string bundleName); protected abstract void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs index ae69dddbc7..b087db517f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.Hosting; @@ -33,9 +34,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers ); } - protected override IReadOnlyList GetBundleFiles(string bundleName) + protected override async Task> GetBundleFilesAsync(string bundleName) { - return BundleManager.GetScriptBundleFiles(bundleName); + return await BundleManager.GetScriptBundleFilesAsync(bundleName); } protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs index 60d45d8f2f..2d273345cb 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.Hosting; @@ -33,9 +34,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers ); } - protected override IReadOnlyList GetBundleFiles(string bundleName) + protected override async Task> GetBundleFilesAsync(string bundleName) { - return BundleManager.GetStyleBundleFiles(bundleName); + return await BundleManager.GetStyleBundleFilesAsync(bundleName); } protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file)