Browse Source

Resolved #2213: Support async for Bundle Contributors.

pull/2214/head^2
Halil İbrahim Kalkan 6 years ago
parent
commit
e8417a461c
  1. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs
  2. 32
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributor.cs
  3. 16
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs
  4. 47
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs
  5. 15
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleContributor.cs
  6. 5
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs
  7. 9
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs
  8. 5
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs
  9. 5
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs

2
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));

32
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)
{

16
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<BundleContributor> _contributors;
private readonly List<IBundleContributor> _contributors;
public BundleContributorCollection()
{
_contributors = new List<BundleContributor>();
_contributors = new List<IBundleContributor>();
}
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<TContributor>()
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<BundleContributor> GetAll()
public IReadOnlyList<IBundleContributor> 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)
{

47
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<BundleManager>.Instance;
}
public virtual IReadOnlyList<string> GetStyleBundleFiles(string bundleName)
public virtual async Task<IReadOnlyList<string>> GetStyleBundleFilesAsync(string bundleName)
{
return GetBundleFiles(Options.StyleBundles, bundleName, StyleBundler);
return await GetBundleFilesAsync(Options.StyleBundles, bundleName, StyleBundler);
}
public virtual IReadOnlyList<string> GetScriptBundleFiles(string bundleName)
public virtual async Task<IReadOnlyList<string>> GetScriptBundleFilesAsync(string bundleName)
{
return GetBundleFiles(Options.ScriptBundles, bundleName, ScriptBundler);
return await GetBundleFilesAsync(Options.ScriptBundles, bundleName, ScriptBundler);
}
protected virtual IReadOnlyList<string> GetBundleFiles(BundleConfigurationCollection bundles, string bundleName, IBundler bundler)
protected virtual async Task<IReadOnlyList<string>> 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<string> GetBundleFiles(List<BundleContributor> contributors)
protected async Task<List<string>> GetBundleFilesAsync(List<IBundleContributor> 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<string> GetDynamicResources(List<BundleContributor> contributors)
protected virtual async Task<List<string>> GetDynamicResourcesAsync(List<IBundleContributor> 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<BundleContributor> GetContributors(BundleConfigurationCollection bundles, string bundleName)
protected virtual List<IBundleContributor> GetContributors(BundleConfigurationCollection bundles, string bundleName)
{
var contributors = new List<BundleContributor>();
var contributors = new List<IBundleContributor>();
AddContributorsWithBaseBundles(contributors, bundles, bundleName);
@ -222,7 +237,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
return contributors;
}
protected virtual void AddContributorsWithBaseBundles(List<BundleContributor> contributors, BundleConfigurationCollection bundles, string bundleName)
protected virtual void AddContributorsWithBaseBundles(List<IBundleContributor> contributors, BundleConfigurationCollection bundles, string bundleName)
{
var bundleConfiguration = bundles.Get(bundleName);

15
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);
}
}

5
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<string> GetStyleBundleFiles(string bundleName);
Task<IReadOnlyList<string>> GetStyleBundleFilesAsync(string bundleName);
IReadOnlyList<string> GetScriptBundleFiles(string bundleName);
Task<IReadOnlyList<string>> GetScriptBundleFilesAsync(string bundleName);
}
}

9
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<AbpTagHelperResourceService> 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<AbpTagHelperResourceService>.Instance;
}
public virtual Task ProcessAsync(
public virtual async Task ProcessAsync(
[NotNull] TagHelperContext context,
[NotNull] TagHelperOutput output,
[NotNull] List<BundleTagHelperItem> 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<BundleTagHelperItem> bundleItems);
protected abstract IReadOnlyList<string> GetBundleFiles(string bundleName);
protected abstract Task<IReadOnlyList<string>> GetBundleFilesAsync(string bundleName);
protected abstract void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file);

5
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<string> GetBundleFiles(string bundleName)
protected override async Task<IReadOnlyList<string>> GetBundleFilesAsync(string bundleName)
{
return BundleManager.GetScriptBundleFiles(bundleName);
return await BundleManager.GetScriptBundleFilesAsync(bundleName);
}
protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file)

5
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<string> GetBundleFiles(string bundleName)
protected override async Task<IReadOnlyList<string>> GetBundleFilesAsync(string bundleName)
{
return BundleManager.GetStyleBundleFiles(bundleName);
return await BundleManager.GetStyleBundleFilesAsync(bundleName);
}
protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file)

Loading…
Cancel
Save